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 indicates int , not float.
  • iterating for , variable of type float obscure.
  • are sure want use floating-point data type, when treat integer? consider using long or decimal.

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

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -