Nicke Manarin Nicke Manarin - 2 months ago 8
C# Question

Formatting double

I have this big number (a

double
):
123456789012345.012345


That should be represented as:
123.456.789.012.345,01
using the
pt-BR
format.

This is the format
{0:###,###,###,###,##0.00}
that I'm using, yet this is the result:

enter image description here

As you can see, after 13 characters, the format starts to round the decimal places. How can we display correctly the number without rounding?

Answer

double only has 15-16 digits of precision, so any significant digits after that are truncated.

decimal has 28-29 digits of precision, and should be used if you need to represent the number as a decimal number without any loss of precision.

Comments