473,242 Members | 1,812 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,242 software developers and data experts.

Formatting Money

If I have an Int64 which is $$$$$cc, what is the best way to format it to a string '$nnnn.cc' ?
Jul 9 '08 #1
4 1603
Ian,

If I understand this correctly, the value is basically the number of
cents, correct?

If that is the case, I would do this (I would say to use a decimal since
you are dealing with money):

Decimal amount = (Decimal) longAmount / 100;

And then call ToString, passing "$####.##", and it should work.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ian Semmel" <is***********@NOKUNKrocketcomp.com.auwrote in message
news:OA****************@TK2MSFTNGP06.phx.gbl...
If I have an Int64 which is $$$$$cc, what is the best way to format it to
a string '$nnnn.cc' ?

Jul 9 '08 #2
You need to call something like this:

Int64 myNum = 123456L; //$1234.56
String myString= String.Format("C",myNum/100);

Is that was you mean? The C means format it as a currency. Hear is a good
cheat sheet for formatting strings:
http://john-sheehan.com/blog/wp-cont...ng-strings.pdf

--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"Ian Semmel" wrote:
If I have an Int64 which is $$$$$cc, what is the best way to format it to a string '$nnnn.cc' ?
Jul 9 '08 #3
Ian Semmel wrote:
If I have an Int64 which is $$$$$cc, what is the best way to format it
to a string '$nnnn.cc' ?
Try study:
http://blog.stevex.net/index.php/str...ing-in-csharp/

Arne
Jul 10 '08 #4
Thanks for your replies, I have a greater insight into formatting now.

I had come to the conclusion that I had to convert the number to decimal (or float) for the formatting to work.

Perhaps I was looking for something akin to the old cobol 'implied decimal point' which could be applied to binary fields to tell
the compiler where to put the '.' in formatted output.

Ian Semmel wrote:
If I have an Int64 which is $$$$$cc, what is the best way to format it
to a string '$nnnn.cc' ?
Jul 10 '08 #5

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

Similar topics

6
by: Colin Fox | last post by:
Hi, all. This feels like a stupid question to me, but I've scoured the Internet (yes, the whole thing! :) and I can't find a single example of using the locale module to format money. So I...
1
by: Tonguc Yumruk | last post by:
I'm trying to format an integer as money. As far as i can see there is no strfmon() in python. I also tried the locale.format("%.2f",100000000,True) way but it does not even made the grouping...
3
by: David Sharp | last post by:
I'm trying to find a way to format a FLOAT variable into a varchar in SQL Server 2000 but using CAST/CONVERT I can only get scientific notation i.e. 1e+006 instead of 1000000 which isn't really...
6
by: David Sharp | last post by:
Once I've converted my floats to chars using STR, is there an easy way to put commas in separating the thousands. i.e. convert 53000000.12 to 53,000,000.12 I'm thinking I'll have to do it...
16
by: Douglas | last post by:
Gday, How would I format a number so that: TheValue = 32500 Displays in the TextBox as: $32,500.00
2
by: Earl | last post by:
Still trying to clean up some datagrid formatting issues from the past. When I bring in money values from a stored procedure, I'm getting 4 decimal places in the grid ( which of course I only...
4
by: Jerry | last post by:
Is it possible to turn off the "$" and "," that appear in "money" formatted columns so I can dump the table in a numeric format? The man page hints that lc_monetary controls the formatting but I...
7
by: Chris | last post by:
Where can I find a fairly comprehensive list of the formatting codes used when data binding. e.g. <%# Bind("Debit", "{0:C}") %>. Specifically formatting a number to 2 decimal places. Regards, Chris.
14
by: Scott M. | last post by:
Ok, this is driving me nuts... I am using VS.NET 2003 and trying to take an item out of a row in a loosely-typed dataset and place it in a label as a currency. As it is now, I am getting my...
2
by: jerryyang_la1 | last post by:
I need some advice on formatting numbers using PHP. My database holds numbers like: 10 0.2 I need these to be displayed as 10.00
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
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...

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.