Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double to String keeping trailing zero

Tags:

c#

I've tried converting the double value into a string and using the Replace() method to replace the ',' to '.'.

This works well but only when the trailing digits are not zero, I need zeros in my string, even if the value is 1234.0. This worked well for the decimal values. I have tried to convert the double to decimal but I lose the decimal digits if there are zeros.

I know I'm missing something. I would be grateful for some suggestions.

like image 305
George Taskos Avatar asked Mar 05 '10 16:03

George Taskos


1 Answers

This would depend on the language. An example in C#

d.ToString("0.00");

Would produce a double with 2 decimal places nomatter the values (zero or otherwise).

like image 96
NebuSoft Avatar answered Sep 23 '22 22:09

NebuSoft