Skip to main content
Participant
October 20, 2008
Question

Thousand and decimal seperators

  • October 20, 2008
  • 6 replies
  • 742 views
Hi all,

I have a question I need to convert a european number (. as thousand seperator and a , as decimal seperator) to an american number. But I could recieve both type of numbers. So when I get an american number delivered I want to do nothing and in case of an european number I want to convert it.

Is there a method to determine what kind of number I'm dealing with?

Cheers,
Rick
    This topic has been closed for replies.

    6 replies

    Inspiring
    October 20, 2008
    fober1 wrote:
    > and local needs to be set to DE_DE.

    that's actually de_DE.
    Inspiring
    October 20, 2008
    Hi,

    When a user enters a number you can use LSParseNumber to convert the entered value into a "real number". You can use LSNumberFormat to format a internal value for display in a local format.

    There are also functions to parse and format dates and currencies.

    All these functions are converting values depending on the local that is set on the page ( with a "SetLocale"-function).

    To be able to parse and format these values you need to be able to identify the local by either having a customer select his country from a listbox / user account, or knowing that the customer went as example to the German site, and local needs to be set to de_DE.

    cheers,
    fober

    (updated the example local)

    Here's an example function to list all the available locals:
    ======================================================
    <table>
    <cfloop index="x" list="#Server.ColdFusion.SupportedLocales#">
    <cfoutput>
    <tr>
    <td>#x#</td>
    <td>#GetLocaleDisplayName(x)#</td>
    </tr>
    </cfoutput>
    </cfloop>
    </table>
    Participating Frequently
    October 20, 2008
    Oh, and if you need your thousand separators then just do this:

    <cfdump var="#LSCurrencyFormat(ConvertToNumber("123.456.789,01"))#">
    <cfdump var="#LSCurrencyFormat(ConvertToNumber("123,456,789.01"))#">
    Participating Frequently
    October 20, 2008
    OK, here's a quick solution...

    <cfdump var="#ConvertToNumber("123.456.789,01")#">
    <cfdump var="#ConvertToNumber("123,456,789.01")#">

    <cfscript>
    function ConvertToNumber(s) {
    var foo = ListChangeDelims( arguments.s, ".", ",.'" );
    var integer = Replace( Left( foo, foo.lastIndexOf(".") ), ".", "", "all" );
    var decimal = ListLast(foo, ".");
    return integer & "." & decimal;
    }
    </cfscript>

    Does that solve your problem?
    WubzorzAuthor
    Participant
    October 20, 2008
    When I have a number say 123.456.789,01 I want to transfer it to 123,456,789.01
    Participating Frequently
    October 20, 2008
    Bit confused by your question, but I would probably use the LSCurrencyFormat(number [, type, locale]) function to display your number. CF8 allows you to pass the locale in so just set it to whatever region you want.