How do I format a float number?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have this problem. I have a method with the following signature: public
float GetBalance().
The problem is that it returns values in the format 4.289418E+07.
What I would like is get something like 428941.80. I do NOT want to return
a string.

I have tried to play around with NumberFormat but with no luck. Anybody
have any ideas on this?

I'm stumped...
 
If you do not want to return a string, then you don't need to do anything
with formatting. A float is a 32-bit binary number.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Who is Mighty Abbott?
A twin turret scalawag.
 
Hello Dilip,

Kevin's correct. You dont need to format until you want to show it out on
the UI, which mean converting it to a string.

If you are thinking about comparing the float value, especially using equality
(==), its better to use decimal instead of floats.

If you are converting/showing this output to the UI, you might use < .ToString("F")
 
Kevin, Ranjan,

Thanks...my confusion was around when to format the value. Formatting only
when displaying is what I should have been looking at.

-Dilip
 
Hi Dilip,

So, are you all set now, or is there still a question?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Who is Mighty Abbott?
A twin turret scalawag.
 
Back
Top