What is the difference between ToString("N2")
and ToString("0.00")
?
The comma can break down-stream code that might have to parse that value back to a decimal, especially client-side js. Actually "N2" will print "3,543.00". --Answer is rp="567.34"; -- N2 gives upto two decimal records. The question asked the difference between ToString ("N2") and ToString ("0.00"), which isn't covered in this answer.
Basically, ToString ("N2") will use the CultureInfo to format the number. This means that your thousands separator might be different depending on the used CultureInfo. You can also pass the desired CultureInfo if you want. Both give you two decimal places, but you can see the difference easily if you check larger numbers:
It would seem that N will include thousands separators, whereas 0.00 will not. N2 will work the same way for 500.00, but when you have 5000.00, N2 will display as
A "G" format specifier that represents a customary or common format of the object. The parameterless overload of your object's ToString method should call its ToString(String) overload and pass it the "G" standard format string. Support for a format specifier that is equal to a null reference (Nothing in Visual Basic).
From Standard Numeric Format Strings
The number is converted to a string of the form "-d,ddd,ddd.ddd…", where '-' indicates a negative number symbol if required, 'd' indicates a digit (0-9), ',' indicates a thousand separator between number groups, and '.' indicates a decimal point symbol.
It would seem that N
will include thousands separators, whereas 0.00
will not.
See also Custom Numeric Format Strings
It's all about the decimal places
N2
will work the same way for 500.00, but when you have 5000.00, N2
will display as
5,000.00
instead of
5000.00
See Standard Numeric Format Strings for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With