I suppose the answer depends on memory constraints of the machine the program runs on. As this used to be an issue years ago, programmers were perhaps inclined to use a data type that didn't utilise much memeory. However, this day and age that doesn't seem to be an issue - therefore the choice, at the end of the day, is up to the programmer.
To create a currency value with 2 decimal places (like in US currency), you have to first start off with the value specified in cents, not dollars & cents:
Code:
Imports System.Globalization
Dim decNum As New Decimal(345, 0, 0, False, 2)
Dim cc As New CultureInfo("en-US")
Console.WriteLine(decNum.ToString("C", cc.NumberFormat))
This will write $3.45 to the command window.
Of course, the Decimal just contains a value, and doesn't know $ from £, so you'll need to store which currency it's in in a separate variable. I recommend you create a new class called IntlMoney which will encapsulate both the value, and the currency it's in.
I don't know why the framework doesn't have something like that.
Chip H.
____________________________________________________________________ If you want to get the best response to a question, please read FAQ222-2244 first
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.