If I have an Int64 which is $$$$$cc, what is the best way to format it to a string '$nnnn.cc' ?
Formatting Money
Collapse
This topic is closed.
X
X
-
Ian SemmelTags: None -
Nicholas Paldino [.NET/C# MVP]
Re: Formatting Money
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]
- mvp@spam.guard. caspershouse.co m
"Ian Semmel" <isemmelNOJUNK@ NOKUNKrocketcom p.com.auwrote in message
news:OA%23QBXf4 IHA.4260@TK2MSF TNGP06.phx.gbl. ..If I have an Int64 which is $$$$$cc, what is the best way to format it to
a string '$nnnn.cc' ?
-
=?Utf-8?B?Q2lhcmFuIE8nJ0Rvbm5lbGw=?=
RE: Formatting Money
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:
--
Ciaran O''Donnell
"Ian Semmel" wrote:
If I have an Int64 which is $$$$$cc, what is the best way to format it to a string '$nnnn.cc' ?
>Comment
-
Ian Semmel
Re: Formatting Money
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' ?Comment
Comment