[html5] How to test for cents currency symbol in javascript

Larry Martell larry.martell at gmail.com
Sun May 25 12:10:08 PDT 2014


Hi Andrew-

On Sat, May 24, 2014 at 8:42 AM, Andrew Byrne <byrneandrew46 at gmail.com> wrote:
> Ouch testing for a symbol!?

Yeah, the specific use case is I have a table of data, some
denominated in $ and some in ¢. It's generated by a PHP script. I need
to sort it on the client side in order of their values so I need to
divide the ¢ denominated ones by 100.

> I'm also thinking its a UTF8 / ISO char set thing.
> But the ¢ is a presentation issue can you test for something a little less
> ambiguous like using modulo to find the presence of a decimal.

Both the $ and ¢ values have a decimal point.

Thanks for the reply!
-larry

> On Sat, May 24, 2014 at 10:19 PM, Larry Martell <larry.martell at gmail.com>
> wrote:
>>
>> I need to test for the cents currency symbol in my JavaScript program.
>>
>> I have a variable with this value:
>>
>> ¢40.36
>>
>> In my program I do this:
>>
>> ax = (a[0][0] == '¢');
>>
>> When my program run ax is False. But from the console it evaluates to
>> True:
>>
>> >>> a[0]
>> "¢40.36"
>> >>> ax
>> false
>> >>> a[0][0] == '¢'
>> true
>> >>> ax = (a[0][0] == '¢')
>> true
>> >>> ax
>> true
>>
>> Can anyone explain this odd inconsistency and tell me how I can test
>> for the cents character?


More information about the Help mailing list