Difference between revisions of "SsParseNum"
From SmartWiki
(→When Using "Show Currency Format in Edit Mode") |
|||
Line 43: | Line 43: | ||
When using the "Show Currency Format in Edit Mode" setting for custom fields, the following syntax must be used: | When using the "Show Currency Format in Edit Mode" setting for custom fields, the following syntax must be used: | ||
− | :<font size="3">'''ssParseNumByCode( ''value'',''emptyok'',' ''code'' ');''' </font> | + | :<font size="3">'''ssParseNumByCode( ''value'',''emptyok'','' 'code' '');''' </font> |
Where: <br / > | Where: <br / > |
Revision as of 10:40, 6 May 2015
This feature uses JavaScript syntax |
Contents
Overview
To convert a number from a formatted string (containing symbols like "$" or "%") to a number using JavaScript you can use a function called ssParseNum.
Syntax
- ssParseNum( value, emptyok );
Where:
Parameter | Description |
---|---|
value | Required. Is the value to be converted to a number (i.e: $5,000.00 and 5,000% will be converted to 5000) |
emptyok | Optional. Is a true/false value
|
Examples
ssParseNum($5,000.50);
Will return: 5000.5
If you wish to display a ratio of two fields that are set to have currency formatting, you should convert the values to numbers using ssParseNum:
ssParseNum([field1])/ssParseNum([field2])
Requirements
This function is part of the sstools.js library and needs to be added to Browser Script custom fields or on template pages, sign-up pages etc. using the following syntax:
<SCRIPT type="text/javascript" language="javascript" src="/sstools.js"></SCRIPT>
When Using "Show Currency Format in Edit Mode"
When using the "Show Currency Format in Edit Mode" setting for custom fields, the following syntax must be used:
- ssParseNumByCode( value,emptyok, 'code' );
Where:
Parameter | Description |
---|---|
value | Required. Is the value to be converted to a number (i.e: $5,000.00 and 5,000% will be converted to 5000) |
emptyok | Optional. Is a true/false value
|
code | Required. The three-letter currency code defined by ISO 4217. Example: JPY for Japanese Yen. |
Example:
- ssParseNumByCode([YER Total revenue],0,"CAD") - ssParseNumByCode([YER Total expenses],0,"CAD")