3-digits Formatting a String
Sometimes, you want to format a string into separated 3-digits to make it easier to read. This is the function to do it. You just need to paste it somewhere in your ASP code (or include it) and call it from anywhere in your code.
Scenario:
input = string eg. "1234567890"
output = string eg. "1,123,456,789"
Function:
function SenFormat(a)
org=a
if len(org)>3 then
do while len(org)>3
sema=left(org,len(org)-3)
semb=right(org,3)
semNew= "," & semb & semNew
org=sema
loop
SenFormat=sema & semNew
else
SenFormat=org
end if
'this is where your customization goes
end function
Of course you can customize the script a bit.
Example1:
Scenario1: Change the separator
input = string eg. "1234567890"
output = string eg. "1.123.456.789"
Change to function:
Replace the "," with "."
semNew= "." & semb & semNew
Example2:
Scenario2: Add the currency sign
input = string eg. "1234567890"
output = string eg. "Rp 1.123.456.789"
Change to function:
Add this code line below the "'this is where your customization goes":
SenFormat = "Rp " & SenFormat
where "Rp" is a currency sign here, you can alter it to suit your currency, such as dollar($), pound(£), yen(¥).
Related Articles
Editor's Picks Articles
Top Ten Articles
Previous Features
Site Map
Content copyright © 2023 by Linawaty. All rights reserved.
This content was written by Linawaty. If you wish to use this content in any manner, you need written permission. Contact Lisa Shea for details.