Number Conversion and Currency Formatting w/ LotusScript

Mindwatering Incorporated

Author: Tripp W Black

Created: 10/24/2012 at 06:59 PM

 

Category:
Notes Developer Tips
LotusScript, Sametime

Task 1:
Need to convert text to number or a number type to another number time where this is a risk of error or overflow.


Task 2:
Need to format a number to either US or Euro currencies.


Task 1 Conversion Solutions:
Use a wrapper function. This allows you to choose to send back 0 in the case of an error or a clearly bogus number (e.g. -999), so that the calling code can handle without a top-level handler added just for the number conversion.

Convert to Long Example:
This example performs conversions with an error handler, and also handles rounding so that when "9.6535" is turned into a Long, it becomes the number 10, and not 9. If there is an error, it returns -999, so that the calling function can see that has the error, not a real conversion and handle appropriately.
LSLong-Function.txtLSLong-Function.txt

Convert to Double Example:
This example converts text to a double and returns it. Unlike the previous example, this one returns 0 if there is an error.
LSDouble-Function.txtLSDouble-Function.txt



Task 2 Currency Solutions:
US (Dollar):

Dim varTxt as Text			' the number/text to be converted to double and formatted as currency
Dim varDbl as Double			' temporary working double to prep for formatting with Format$ function
...
varDbl = LSCDbl(varTxt)
Format$(varDbl, "Currency")		'  or Format(varDbl, "Standard")
...


Euro:

Dim varTxt as Text			' the number/text to be converted to double and formatted as currency
Dim varDbl as Double			' temporary working double to prep for formatting with Format$ function
...
Format$(varDbl, "€#.##0,00")


Notes:
- Use the LSCDbl function above to convert the number to a Double first. Then
- Above snippets assumes database/application currency type is US Dollars. Otherwise, they will return currency to the server's/app's currency default.
- varDbl can be number or string with Format$, but we convert to the text to double for predictability in handling invalid numbers


previous page

×