c# - How can i convert a float number to a string? -
how can convert float number string?
for (float = 1000000000; < 10000000000; i++) { //temp never change , it's value 1000000000 string temp = convert.toint64(i).tostring(); }
this number big , want save string on file like
1000000001 1000000002 1000000003
how can convert float number string?
obviously: i.tostring()
. see the documentation learn how apply formatting in order achieve desired output.
however, couple notes:
- a variable named
i
commonly indicatesint
, notfloat
. - iterating
for
, variable of typefloat
obscure. - are sure want use floating-point data type, when treat integer? consider using
long
ordecimal
.
temp never change , it's value 1000000000
float
's precision not enough store number big 1000000000
, discards least significant places. wikipedia: “all integers 6 or less significant decimal digits can converted ieee 754 floating point value.” that's why result seems same. side effect, for
cycle never end.
hence, first of all, ask why have declared variable being of type float
at first place? because of conversion long
in code, anyway. consider using long
or maybe decimal
. code work.
Comments
Post a Comment