473,698 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
--

fiddlewidawiddu m
Oct 31 '06 #1
7 1973
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.com wrote in message
news:sl******** ********@murphy .redbrick.dcu.i e...
>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
--

fiddlewidawiddu m

Oct 31 '06 #2
Stimp,

Use the format 'f'

Example:

int myInt = 24;
Console.WriteLi ne("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.c omwrote:
Stimp,

Use the format 'f'

Example:

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

Should output:

My Int : 24.00

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

--

fiddlewidawiddu m
Oct 31 '06 #4

There are many ways to string.Format:

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

string.Format(" {0:###,###,###, ##0.00;-#,###,###,##0.0 0;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.
--

fiddlewidawiddu m
Nov 1 '06 #6
..ToString("#.0 0") ??

(Note the dot, which maight be culture depending)
"Stimp" <re*@spumco.com schreef in bericht
news:sl******** ********@murphy .redbrick.dcu.i e...
>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
--

fiddlewidawiddu m

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************* ***@murphy.redb rick.dcu.ie...

There are many ways to string.Format:

string.Format( "{0:###,###,### ,##0.00;-#,###,###,##0.0 0;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.
--

fiddlewidawiddu m

Nov 2 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
37137
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 this? I have seen it mostly I think with netscape,
2
3850
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 can set format for a ultrawebgrid column.(for eg. Me.uwgTest.Columns(15).Format=CultureInfo.NumberFormat)
12
13900
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 does not support it. Could someone helps me please? The example table: T1 (col1 varchar(7) not null,
5
1980
by: ABC | last post by:
How to initial the datetime variable as value to "01/01/2005 00:00:00"?
5
70422
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 format the number as mentioned in the subject line.
4
2241
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 the same issue?
6
21801
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? Thanks,
0
1591
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 will become 5.10. If they enter 1.239 it will become 1.24. Thanks for the help.
3
12326
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, but not sure how to convert the number. Thanks for the help.
0
8604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8862
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7729
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6521
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.