Difference between revisions of "SsParseNum"

From SmartWiki
Jump to: navigation, search
(Created page with 'The ''ssParseNum'' syntax is used in JavaScript expressions ==See Also== * SsFormatCurrency Category:JavaScriptCategory:Currency')
 
Line 1: Line 1:
 
The ''ssParseNum'' syntax is used in JavaScript expressions  
 
The ''ssParseNum'' syntax is used in JavaScript expressions  
 +
 +
==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==
 +
:<font size="3">'''ssParseNum( ''value'', ''emptyok'' );''' </font>
 +
 +
Where: <br / >
 +
<b><em>value </em></b>- 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 </em></b>- 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''
 +
 +
 +
==Example==
 +
<pre>
 +
ssParseNum($5,000.00,true);
 +
</pre>
 +
 +
Will return: 5000
 +
 +
 +
==Requirements==
 +
This function is part of the <b>sstools.js</b> 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>
 +
  
 
==See Also==
 
==See Also==

Revision as of 14:23, 18 November 2013

The ssParseNum syntax is used in JavaScript expressions

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 - is the a value to be converted to a number (i.e: $5,000.00 and 5,000% will be converted to 5000)
emptyok - 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


Example

ssParseNum($5,000.00,true);

Will return: 5000


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>


See Also