Home All Groups Group Topic Archive Search About

How do I format a float number?

Author
19 Jan 2006 12:37 PM
Dilip M
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...

Author
19 Jan 2006 3:35 PM
Kevin Spencer
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.

Show quote
"Dilip M" <Dil***@discussions.microsoft.com> wrote in message
news:2B2EAE09-863B-41AD-B66E-54EC45DBC89F@microsoft.com...
>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...
Author
19 Jan 2006 6:49 PM
Ranjan Sakalley
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")
>

r.

Show quote
> 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...
>
Author
20 Jan 2006 3:31 AM
Dilip M
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

Show quote
"Ranjan Sakalley" wrote:

> 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")
> >
>
> r.
>
> > 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...
> >
>
>
>
Author
20 Jan 2006 11:17 AM
Kevin Spencer
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.

Show quote
"Dilip M" <Dil***@discussions.microsoft.com> wrote in message
news:670C052E-696E-4964-939A-02FB40A5B1F4@microsoft.com...
> 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
>
> "Ranjan Sakalley" wrote:
>
>> 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")
>> >
>>
>> r.
>>
>> > 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...
>> >
>>
>>
>>

AddThis Social Bookmark Button