[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Format currency in ASp.Net

Posted on 2007-04-02
17
Medium Priority
?
1,198 Views
Last Modified: 2008-01-09
I found this link and been trying to format the text displayed to currency but not getting the right format:
http://msconline.maconstate.edu/tutorials/ASPNET2/ASPNET07/aspnet07-01.aspx
I want:
$48,300.00, $615,23.00 , $0.80 , $39.00

This is what I have and what i've tried:
DataTextFormatString={0:#,#.##} -- 48300,00 --> 48.300
                                   615,23 -> remains the same
                                   0,80 --> ,8
                                   39,00 --> 39

Tried:{0:$#,#.##} : same results except it has $
Tried : {0:0.00} : goes back to orig #s that have commas . Ex: 48300,00
Tried : (0:C} . With this 48,300 shows as : 48.300,0

what to do?
0
Comment
Question by:Camillia
[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
  • Learn & ask questions
  • 8
  • 8
17 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18836943
Why not use the function FormatCurrency?

txtValue.Text=FormatCurrency(YourCurrency, 2)
0
 
LVL 7

Author Comment

by:Camillia
ID: 18837077
i'm binding to a gridview, If I want to use FormatCurrecny, I have to do it in itemdatabound event??
0
 
LVL 25

Accepted Solution

by:
dstanley9 earned 2000 total points
ID: 18837085
What culture is the server using?  FormatCurrency will use the format defiend by the system's culture (presumably the same format that {0:C} uses.

Try

={0:'$'#,##0.00}

The zero placeholders will dispaly a 0 if there is no digit there, the # will not.
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 25

Expert Comment

by:dstanley9
ID: 18837089
Also the $ will display the currency defined by the system.  If the system does not define a currency symbol, none will be used.
0
 
LVL 7

Author Comment

by:Camillia
ID: 18837145
no, that didnt do it either. I think I have to use FormatString.

The culture in my browser is english-US.

I dont want to display the "$".  (i just realized it). I just want to display the value correctly:
12,999.89 for example..

I think I have to use FormatString...but in itemdatabound??
0
 
LVL 7

Author Comment

by:Camillia
ID: 18837158
if I dont want the "$", I think i have to use FormatNumber...but again, in itemdatabound?
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 18837171
It's the culture on the _server_ that is used, not in the browser.

If you don't  want the currency symbol, just use ={0:#,##0.00}
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 18837205
You shouldn't have to use FormatNumber.  DataTextFormatString should format it the way you want if you use the right string.

FormatNumber will also use the settings in the _server's_ control panel.  So it will use commas instead of decimal points based on your examples above.
0
 
LVL 7

Author Comment

by:Camillia
ID: 18837241
***************does NOT format it correctly. I just tried it: *****************

If you read my orig post, i've tried several things and still no.  *** I want to try FormatNumber but since i'm binding to gridview, I think i have to do the formatting in itemdatabound****

I tired your last suggestion :
48300,00  shows up at 48.300,00
39,00 still shows up as 39,00 instead of 39.00
0
 
LVL 7

Author Comment

by:Camillia
ID: 18837259
just saw your other msg:

"FormatNumber will also use the settings in the _server's_ control panel"...where do I check that??
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 18837604
Start-->Control Panel-->Regional and Language Options
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 18837625
OK So the , and . placeholders must use the regional settings as well.  
0
 
LVL 7

Author Comment

by:Camillia
ID: 18837960
ah, this is what I see:

For currecny : $123,456,789.00
and for number : 123,456,789.00

Still dont understand why 48300,00  shows up as 48.300,00
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 18838092
Hmm.  The site is not changing the culture of the thread someplece else, is it?
0
 
LVL 7

Author Comment

by:Camillia
ID: 18838180
I can step thru the code but i dont think so. I just get the total in the stored proc and bind it... this is what i used in the aspx page, in the gridview:
{0:#,##0.00}

just noticed it...that does have a "dot" in it...after the second zero and before the double zeros. is that why??
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 18839288
The format code tells .NET to use groupings of 3 separated by a comma (The ##0 between the comma and . define the grouping size.  The first zero says to make sure that at least one digit is displayed to the left of the decimal (even if it's a zero) and the two zeros on the right of the decimal tell it to always show two digits to the right of the decimal (even if one or both are zeros).

Something must be changing either the culture or the default NumberFormatInfo.  Double.ToString() Uses the default NumberFormatInfo to convert to a string.  You can look at System.Globalization.NumberFormatInfo.CurrentInfo
and System.Threading.Thread.CurrentCulture in the debugger and see what culture and separator characters are being used.
0
 
LVL 7

Author Comment

by:Camillia
ID: 18839388
i'll track it down and see what's going on. Will post back.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question