|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How do I format a float number?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. -- Show quoteHTH, Kevin Spencer Microsoft MVP ..Net Developer Who is Mighty Abbott? A twin turret scalawag. "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... 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... > 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... > > > > > Hi Dilip,
So, are you all set now, or is there still a question? -- Show quoteHTH, Kevin Spencer Microsoft MVP ..Net Developer Who is Mighty Abbott? A twin turret scalawag. "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... >> > >> >> >> |
|||||||||||||||||||||||