|
-
Feb 16th, 2006, 03:10 AM
#1
Thread Starter
Frenzied Member
Help with converting currency
Im working in vs 2003 and im developing a web app for our financial department.
On the last meeting they made a somewhat strange request..
They want all currency to be represented like this:
45 000,50 = correct (45 and a half milllion)
So I tried using the cultureinfo of swedish, and to my surprise it became:
4.550.000,00 kr which is swedish currency.
I asked the economist and he said his format was SS ISO 31-0
How is it possible for me to convert a decimal number to his format?? I mean without writing 100 lines of cumbersome logic and string parsing...
/Henrik
-
Feb 16th, 2006, 04:32 AM
#2
Re: Help with converting currency
I don't understand how either of those numbers represent 45,500,000 (forty five and a half million). The first one looks like it would be either 45,000.5 (forty five thousand point five) or 4,500,050 (four million, five hundred thousand and fifty) while the second looks like 4,550,000 (four million, five hundred and fifty thousand) or 455,000,000 (four hundred and fifty five million). I don't understand the correspondence.
-
Feb 16th, 2006, 04:37 AM
#3
Thread Starter
Frenzied Member
Re: Help with converting currency
I agree, I dont understand it either... but I got a pdf document from our economy department that showed this very strange way of converting currency... it is an SS ISO standard... but I guess its not that well known.... 
/henrik
-
Feb 16th, 2006, 04:54 AM
#4
Re: Help with converting currency
I have never seen that before. Sounds like a horrible and confusing format.
Looks like you'll need to write some cumbersom code, unfortunately
Edit: Are these standards and PDFs available online?
-
Feb 16th, 2006, 05:14 AM
#5
Re: Help with converting currency
I just had a Google and it seems that that ISO standard is saying that a comma should be used as a decimal sign and a space should be used as a thousand marker, so all you'd have to do to convert that second number to ISO 31-0 would be remove the "." thousand markers. To format numbers in a specific way you need to create a Globalization.NumberFormatInfo object and set the properties appropriately. You can then pass that object to any methods that require an IFormatProvider, like myNumber.ToString("c", myNumberFormatInfo) to format a number as currecy using your format.
-
Feb 16th, 2006, 06:45 AM
#6
Re: Help with converting currency
Further, here's how you can create a NumberFormatInfo object that will conform to that standard for currency regardless of system settings:
VB Code:
'Use the current number format as a base.
Dim nfi As Globalization.NumberFormatInfo = Globalization.NumberFormatInfo.CurrentInfo
'Use a comma as the currency decimal symbol.
nfi.CurrencyDecimalSeparator = ","
'Use a space as the currency group seperator.
nfi.CurrencyGroupSeparator = " "
You would probably create this object as a global variable and then use it whenever displaying currency values. Note that you can do the same for regular numbers too. There is almost certainly a way to have your application use this NumberFormatInfo by default but I'm not sure what it is. You can't save it back to the CurrentInfo property as that's ReadOnly. Perhaps you can simply change some of the property values of the CurrentInfo and they will become the default sfro the app. Some things for you to play with anyway.
-
Feb 16th, 2006, 06:52 AM
#7
Thread Starter
Frenzied Member
Re: Help with converting currency
Thank you so much for your efforts!! I will implement some kind of solution based on your findings!
/henrik
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|