472,119 Members | 1,556 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

how to output a number like "20.00"

I want to output a number, say 20, as 20.00

i.e. I want to always have 2 decimal places

I don't want any currency information, therefore String.Format("{0:c}")
doesn't work for me.

Can't seem to find a way to do this. Any ideas?

Thanks,
Peter
--

fiddlewidawiddum
Oct 31 '06 #1
7 1894
http://msdn2.microsoft.com/en-us/library/1ksz8yb7.aspx

Try N

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************************************************
Think outside of the box!
*************************************************
"Stimp" <re*@spumco.comwrote in message
news:sl****************@murphy.redbrick.dcu.ie...
>I want to output a number, say 20, as 20.00

i.e. I want to always have 2 decimal places

I don't want any currency information, therefore String.Format("{0:c}")
doesn't work for me.

Can't seem to find a way to do this. Any ideas?

Thanks,
Peter
--

fiddlewidawiddum

Oct 31 '06 #2
Stimp,

Use the format 'f'

Example:

int myInt = 24;
Console.WriteLine("My Int : {0:f}", myInt);

Should output:

My Int : 24.00

Hope that helps, Basil

Stimp wrote:
I want to output a number, say 20, as 20.00

i.e. I want to always have 2 decimal places

I don't want any currency information, therefore String.Format("{0:c}")
doesn't work for me.

Can't seem to find a way to do this. Any ideas?

Thanks,
Peter
Oct 31 '06 #3
On Tue, 31 Oct 2006 Basil Abusamrah <te****@gmail.comwrote:
Stimp,

Use the format 'f'

Example:

int myInt = 24;
Console.WriteLine("My Int : {0:f}", myInt);

Should output:

My Int : 24.00

Hope that helps, Basil
that worked great. thanks! :)

--

fiddlewidawiddum
Oct 31 '06 #4

There are many ways to string.Format:

string.Format("{0:###,###,###,##0.00;-#,###,###,##0.00;0.00}", YourValue);
Oct 31 '06 #5
>
There are many ways to string.Format:

string.Format("{0:###,###,###,##0.00;-#,###,###,##0.00;0.00}", YourValue);
That actually doesn't work for what I needed though. I had tried it.

#.## only outputs 20 instead of "20.00" or 20.1 instead of "20.10" etc.

{0:f} is the best way to go.
--

fiddlewidawiddum
Nov 1 '06 #6
..ToString("#.00") ??

(Note the dot, which maight be culture depending)
"Stimp" <re*@spumco.comschreef in bericht
news:sl****************@murphy.redbrick.dcu.ie...
>I want to output a number, say 20, as 20.00

i.e. I want to always have 2 decimal places

I don't want any currency information, therefore String.Format("{0:c}")
doesn't work for me.

Can't seem to find a way to do this. Any ideas?

Thanks,
Peter
--

fiddlewidawiddum

Nov 1 '06 #7
it's not #.## but #0.00, through.

# is a optional digits placeholder(i.e.: has output only when it's a
significant digit), while 0 is arbitary (i.e.: it has output regardless of
whether it's significant or not.)

P.S.: the above paragraph requires you to treat 20 as ...0000020.0000...
where the empty place is in fact filled with 0.

"Stimp" <re*@spumco.com¼¶¼g©ó¶l¥ó·s»D:sl****************@m urphy.redbrick.dcu.ie...

There are many ways to string.Format:

string.Format("{0:###,###,###,##0.00;-#,###,###,##0.00;0.00}",
YourValue);

That actually doesn't work for what I needed though. I had tried it.

#.## only outputs 20 instead of "20.00" or 20.1 instead of "20.10" etc.

{0:f} is the best way to go.
--

fiddlewidawiddum

Nov 2 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by stevong | last post: by
reply views Thread by Ronald S. Cook | last post: by
3 posts views Thread by Ronald S. Cook | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.