473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 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 1948
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: barb28 | last post by:
Hello, sometimes I have noticed that in web addresses, the number: 20% will show up in the address. I think this is somehow related to a 'blank space', but am unsure, does anyone know about...
2
by: kiran | last post by:
Hi, I am able to create instance of Culture Info for different cultures. How will I get number format as "$ ###,###,##0.00" from CultureInfo.NumberFormat. I need it in this format so that I...
12
by: Emi Lu | last post by:
Hello all, I have a question about "date" & "timestamp" types in PostgreSQL. I want to setup the default value '0000-00-00' and "0000-00-00 00:00:00" for them. However, it seems that PostgreSQL...
5
by: ABC | last post by:
How to initial the datetime variable as value to "01/01/2005 00:00:00"?
5
by: Bob | last post by:
Hello Folks, I am bring backa data reader dr from the database/ So I have a number of fields such as dr To put this in a table I use "<td>" + dr.ToString() + "</td>" But I want to...
4
by: stevong | last post by:
Hi everyone, I have a mailing list generated from php and sent out by mail(). But i often have broken graphics due to the fact that it randomly appends %20 to the html output! Anybody has...
6
by: Bob | last post by:
Hello folks. I use this formating but if the value in dr is a null it generates an error "Object cannot be cast from DBNull to other types." Anybody know how I can deal with nulls? ...
0
by: Ronald S. Cook | last post by:
Stupid question for the day but weirdly I don't have this yet. How can I format a textbox such that if the user enters a number like 4 it will become (on validated) 4.00. If they enter 5.1 it...
3
by: Ronald S. Cook | last post by:
Stupid q for the day, but if the user enters 2 in a textbox, I want to display as 2.00. If they enter 2.129 I want it as 2.13. I'm guessing will code in the validated method of the textbox,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.