Solved

# Format currency and percentage

Posted on 2006-11-20
8,286 Views
hi EE
I would like to format currency and percentages as follows:

1) Currency - thousand seperator and accuracy to 2 decimal places (rounding to 2 decimal points if 3 digits given after the decimal pt)

ex: 3,001.987 --> 3,001.99

2) Percentage - accuracy to 2 decimal places (rounding to 2 decimal points if 3 digits given after the decimal pt)

What would be the correct string format in order to format to these specifications?
thx
0
Question by:LuckyLucks
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 4

LVL 35

Expert Comment

ID: 17980011
currency:
String.Format("{0:C}", 1234.56)

percentage

String.Format("{0:P}", .1234)
0

LVL 35

Accepted Solution

YZlat earned 500 total points
ID: 17980092
String.Format("{0:C2}", 1234.56)

String.Format("{0:P2}", .1234)
0

LVL 7

Expert Comment

ID: 17981077
What YZlat will work fine. Another example follows. Say, for example, you were storing your values as either Single or Double objects like so:

Dim myMoney As Double = 2000.356
Dim myPercent As Double = 0.15797

myMoney.ToString("c") 'returns \$2,000.36
myPercent.ToString("p") 'returns 15.80 percent as the 9 rounds the 7 to an 8. Unsure how you would force it to remain unrounded

But that's the method I always use since the ToString() function on those datatypes supports it.

Good luck!
0

Author Comment

ID: 17981415
YZlat,
Not sure if I am doing something incorrect but when I try for the percentage an example .07657
it will display it as 7.65 whereas I was looking for 7.66.

Also, since the string format P2 first multiplies the input by 100 and then displays it, something like 7.50 will display as 750.00 , is there a way to turn this multiplication factor off?
0

LVL 35

Expert Comment

ID: 18031800
LuckyLucks, I just tried

Dim number As Double = 0.07657
Label1.Text = String.Format("{0:P2}", number)

and Label1 displayed 7.66%
0

LVL 35

Expert Comment

ID: 18031854
also 7.50 in percentages will be 750.00. That's the way percentage is calculated. What would you want to be displayed instead of 7.5??

0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
###### Suggested Courses
Course of the Month6 days, 2 hours left to enroll