By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,566 Members | 1,774 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,566 IT Pros & Developers. It's quick & easy.

Formatting Money

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.