g
Printer Friendly Version

editor  
BellaOnline's ASP Editor
 

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(¥).

This site needs an editor - click to learn more!

ASP Site @ BellaOnline
View This Article in Regular Layout

Content copyright © 2011 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 Editor Wanted for details.



| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2013 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor