Any smart way to convert a float like this:
float f = 711989.98f;
into a decimal (or double) without losing precision?
I’ve tried:
decimal d = (decimal)f;
decimal d1 = (decimal)(Math.Round(f,2));
decimal d2 = Convert.ToDecimal(f);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s too late, the 8th digit was lost in the compiler. The float type can store only 7 significant digits. You’ll have to rewrite the code, assigning to double or decimal will of course solve the problem.