Skip to content

Instantly share code, notes, and snippets.

@orangexception
Created August 6, 2012 19:40
Show Gist options
  • Save orangexception/3277875 to your computer and use it in GitHub Desktop.
Save orangexception/3277875 to your computer and use it in GitHub Desktop.
CTXNumberFormat
function CTXNumberFormat( dNumber ) {
dNumber= DecimalFormat( dNumber );
dNumber= dNumber.ReplaceAll( "(\.0+|\.(\d)0)$" , ".$2" );
dNumber= dNumber.ReplaceAll( "," , "" );
dNumber= dNumber.ReplaceAll( "\.$" , "" );
dNumber= dNumber.ReplaceAll( "^0+" , "" );
return dNumber;
}
@orangexception
Copy link
Author

CTX Format requires that needless 0's, including leading 0's, and decimal places are removed.

Examples {input} becomes {output}:
0.01 => .01
10.00 => 10
10.10 => 10.1
10.01 => 10.01

@orangexception
Copy link
Author

4+ digit numbers were including commas. I added a line to remove those as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment