tags:

views:

258

answers:

3

I'm having this issue and i cant think for the best solution, i tried converting the double value into a string and Replace() the ',' to '.'. This works good but only when trailing digits are not zero, i need zeros in my string, even if the value is 1234.0. This worked good for the decimal values. Tried to convert the double to decimal but i loose the decimal digits of there are zeros.

[EDIT] Sorry forgot to mention C#.NET

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

Thank you

+3  A: 

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).

NebuSoft
Thanx worked great :)
http://msdn.microsoft.com/en-us/library/system.object.tostring.aspx
Brian T Hannan
A: 

If this is in Java, check out the NumberFormat class's setMinimumFractionDigits() method.

Example:

double d1 = 2.5;
double d2 = 5.0;

NumberFormat nf = NumberFormat.getInstance();
nf.setMinimumFractionDigits(2);

String d1s = nf.format(d1);
String d2s = nf.format(d2);

System.out.println("d1s: " + d1s + " and d2s: " + d2s);

produces

d1s: 2.50 and d2s: 5.00

Lord Torgamus
+1  A: 

...and in Fortran, you could do something like: :-)

      write(*,110) x
  110 format (F5.3)

(guess we really have to know what language is being used...)

David Gelhar
+1: I was going to delete my answer -- now that the OP said C# -- but after reading your answer I think I'll leave it.
Lord Torgamus