Trailing zeros and floats

  • Thread starter Thread starter V. Jenks
  • Start date Start date
V

V. Jenks

I need to store money values in C# and I noticed when using
a float, the trailing zero was trimmed off automatically.
I don't want this, is there a native type that will *not*
do this so I can have my trailing zeros?

I want $0.10 not $0.1.....obviously that gives me serious
data issues.

Thanks!

-v
 
I need to store money values in C# and I noticed when using
a float, the trailing zero was trimmed off automatically.
I don't want this, is there a native type that will *not*
do this so I can have my trailing zeros?

I want $0.10 not $0.1.....obviously that gives me serious
data issues.

Either way the actual numerical value is .1. You are talking display value
vs stored value. If you want to display a number formatted to two decimal
places, then you use the appropriate format string.
 
Hi,

Please note that you are confusing two different things, how the number is
store as a number and how it's displayed either as a number or as a
currency.
if you do double_var.ToString() it will remove the trailing 0 , if you do
double_var.ToString("C") you will get the currency representation of that
number.

Cheers,
 
<"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.machin AT
dot.state.fl.us> said:
Please note that you are confusing two different things, how the number is
store as a number and how it's displayed either as a number or as a
currency.
if you do double_var.ToString() it will remove the trailing 0 , if you do
double_var.ToString("C") you will get the currency representation of that
number.

Note, however, that decimals *do* keep their trailing zeroes (in stored
form) as of 1.1. Decimal tends to be better for financial purposes
anyway.
 
Back
Top