Results 1 to 7 of 7

Thread: Help with converting currency

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602

    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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602

    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

  4. #4
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    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?
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. 'Use the current number format as a base.
    2.         Dim nfi As Globalization.NumberFormatInfo = Globalization.NumberFormatInfo.CurrentInfo
    3.  
    4.         'Use a comma as the currency decimal symbol.
    5.         nfi.CurrencyDecimalSeparator = ","
    6.  
    7.         'Use a space as the currency group seperator.
    8.         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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602

    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
  •  



Click Here to Expand Forum to Full Width