Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Thousand and decimal seperators

New Here ,
Oct 20, 2008 Oct 20, 2008
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
620
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 20, 2008 Oct 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 20, 2008 Oct 20, 2008
When I have a number say 123.456.789,01 I want to transfer it to 123,456,789.01
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 20, 2008 Oct 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?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 20, 2008 Oct 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"))#">
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 20, 2008 Oct 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>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 20, 2008 Oct 20, 2008
LATEST
fober1 wrote:
> and local needs to be set to DE_DE.

that's actually de_DE.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources