471,342 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,342 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 1494
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Colin Fox | last post: by
1 post views Thread by Tonguc Yumruk | last post: by
6 posts views Thread by David Sharp | last post: by
16 posts views Thread by Douglas | last post: by
4 posts views Thread by Jerry | last post: by
7 posts views Thread by Chris | last post: by
14 posts views Thread by Scott M. | last post: by
2 posts views Thread by jerryyang_la1 | last post: by

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.