TextBox and decimal numbers

  • Thread starter Thread starter Alberto
  • Start date Start date
A

Alberto

I have a textbox and when I ttry to insert a decimal number like 900000,99
in this way:

txt.Text = number.ToString();

I see 900001.

It only happens in a proyect but I don't see why.
Can somebody help me?
Thank you?
 
Hi Alberto,

Try changing the type of your number to a double or decimal, rather than a
float.

Joe
 
The only way I could get the same results as you was to set number to type
float. I tried this but it didn't reproduce the problem:

decimal number = 900000.99m;
string text = number.ToString();
Console.WriteLine(text);

How is number being set and how did you verify its value before calling
ToString()? Maybe you could post a small snippet of code that reproduces
the problem. What is your locale set to? Mine is en-US.

Joe
 
Back
Top