By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,028 Members | 1,784 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,028 IT Pros & Developers. It's quick & easy.

how to output a number like "20.00"

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

There are many ways to string.Format:

string.Format("{0:###,###,###,##0.00;-#,###,###,##0.00;0.00}", YourValue);
Oct 31 '06 #5

P: n/a
>
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

P: n/a
..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

P: n/a
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.comglsD: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.