Clean up and streamline thousands separator function.
This commit is contained in:
parent
b3bc25d5c0
commit
5c19c6fe50
2 changed files with 11 additions and 17 deletions
|
|
@ -279,9 +279,11 @@ Class SWWMUtility
|
|||
return c;
|
||||
}
|
||||
|
||||
// not sure if I should use this, looks a bit ugly
|
||||
static clearscope void ThousandsStr( out String s, int col = -1 )
|
||||
// bit ugly, but it works
|
||||
static clearscope void ThousandsStr( out String s, int col = Font.CR_UNDEFINED, String colstr = "" )
|
||||
{
|
||||
if ( (col < Font.CR_UNDEFINED) || (col >= Font.NUM_TEXT_COLORS) )
|
||||
ThrowAbortException("col parameter out of range, use colstr for non-standard font colors.");
|
||||
String nstr = s;
|
||||
s.Truncate(0);
|
||||
int len = nstr.CodePointCount();
|
||||
|
|
@ -295,26 +297,18 @@ Class SWWMUtility
|
|||
t = (t-1)%3;
|
||||
if ( (pos < len) && !t )
|
||||
{
|
||||
if ( col != -1 )
|
||||
{
|
||||
s.AppendCharacter(0x1C);
|
||||
s.AppendCharacter(0x61+col);
|
||||
}
|
||||
s.AppendCharacter(0x2C);
|
||||
if ( col != -1 )
|
||||
{
|
||||
s.AppendCharacter(0x1C);
|
||||
s.AppendCharacter(0x2D);
|
||||
}
|
||||
if ( colstr != "" ) s.AppendFormat("\c[%s],\c-",colstr);
|
||||
else if ( col != Font.CR_UNDEFINED ) s.AppendFormat("\c%c,\c-",0x61+col);
|
||||
else s.AppendCharacter(0x2C);
|
||||
}
|
||||
}
|
||||
}
|
||||
static clearscope String ThousandsNum( int n, int col = -1, int digits = 0 )
|
||||
static clearscope String ThousandsNum( int n, int col = Font.CR_UNDEFINED, String colstr = "", int digits = 0 )
|
||||
{
|
||||
String nstr;
|
||||
if ( digits > 0 ) nstr = String.Format("%0*d",digits,n);
|
||||
else nstr = String.Format("%d",n);
|
||||
ThousandsStr(nstr,col);
|
||||
ThousandsStr(nstr,col,colstr);
|
||||
return nstr;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue