Difference between revisions of "SsParseNum"
From SmartWiki
(→Syntax) |
(→Syntax) |
||
Line 7: | Line 7: | ||
Where: <br / > | Where: <br / > | ||
− | <b><em>value </em></b>- | + | <b><em>value </em></b>- Required. Is the a value to be converted to a number (i.e: $5,000.00 and 5,000% will be converted to 5000)<br /> |
− | <b><em>emptyok | + | <b><em>emptyok </em></b>- Required. Is a true/false value |
:*if ''emptyok'' is true - an empty string will be returned by ssParseNum if the value is ''empty'' | :*if ''emptyok'' is true - an empty string will be returned by ssParseNum if the value is ''empty'' | ||
:*if ''emptyok'' is false - a "0" will be returned by ssParseNum if the value is ''empty'' | :*if ''emptyok'' is false - a "0" will be returned by ssParseNum if the value is ''empty'' |
Revision as of 14:39, 18 November 2013
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:
value - Required. Is the a value to be converted to a number (i.e: $5,000.00 and 5,000% will be converted to 5000)
emptyok - Required. Is a true/false value
- if emptyok is true - an empty string will be returned by ssParseNum if the value is empty
- if emptyok is false - a "0" will be returned by ssParseNum if the value is empty
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>