1

Here is my Problem.

I need to Convert say "5.550" (string) to double as 5.550 that is double with 3 decimal digits. i have tried IFormatProvider while parsing but no use.it keeps skipping last zero(). Please advice.

Thanks, Kumar M A

kumar
  • 51
  • 4
  • 1
    There is no such thing as "keeping the zero on a double" when it's a trailing zero at the end of the decimal point. The value is 5.55. You can format it to a string with an extra zero, but the ACTUAL value is still 5.55 – Adam Plocher Oct 24 '13 at 19:18
  • how do you even _know_ that it is skipping the last zero? If it's by printing it on screen, that is where you can format the trailing zero back in... Can you share your relevant code demonstrating your issue? – Paolo Falabella Oct 24 '13 at 19:21
  • If you're trying to get a double which is 5.550 you won't be able to as the last zero is just meaningless (also it cannot be represented in binary code), also I see no need to do this, again, it means nothing, if you want to print it in such a way you can use string formatting, but otherwise there is no point. – Matan Shahar Oct 24 '13 at 19:21

1 Answers1

2

double doesn't keep insignificant digits - there's no difference between 1.5 and 1.50000 as far as double is concerned.

If you want to preserve insignificant digits, use decimal instead. It may well be more appropriate for you anyway, depending on your exact context. (We have very little context to go on here...)

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194