From ebfc9c3f8d740414b13fff86bad44d077d7ae81e Mon Sep 17 00:00:00 2001 From: Emistry Date: Wed, 15 Jul 2015 01:09:05 +0800 Subject: Follow up d93ed2a26dab220632d523caea0358d33dda7051 Returns a number with commas based on precision of digits and custom separator. -- callfunc "F_InsertComma",{,,} Examples: callfunc("F_InsertComma",7777777{,,}) // returns "7,777,777" callfunc("F_InsertComma",1000000000,3,","}) // returns "1,000,000,000" callfunc("F_InsertComma",1000000000,3,"_"}) // returns "1_000_000_000" callfunc("F_InsertComma",1000000000,4) // returns "10,0000,0000" --- npc/other/Global_Functions.txt | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'npc/other') diff --git a/npc/other/Global_Functions.txt b/npc/other/Global_Functions.txt index 0475ff0a8..b88fa647a 100644 --- a/npc/other/Global_Functions.txt +++ b/npc/other/Global_Functions.txt @@ -39,22 +39,36 @@ //= 2.16 Added F_GetWeaponType, and F_GetArmorType. [L0ne_W0lf] //= 2.17 Renamed 'F_RandMes' to 'F_Rand'. [Euphy] //= 2.18 Removed useless 'getJobName' function. [Euphy] +//= 2.19 Improved 'F_InsertComma' function. [Emistry] //============================================================ ////////////////////////////////////////////////////////////////////////////////// -// Returns a number with commas between every three digits. -// -- callfunc "F_InsertComma", +// Returns a number with commas based on precision of digits and custom separator. +// -- callfunc "F_InsertComma",{,,} // Examples: -// callfunc("F_InsertComma",7777777) // returns "7,777,777" +// callfunc("F_InsertComma",7777777{,,}) // returns "7,777,777" +// callfunc("F_InsertComma",1000000000,3,","}) // returns "1,000,000,000" +// callfunc("F_InsertComma",1000000000,3,"_"}) // returns "1_000_000_000" +// callfunc("F_InsertComma",1000000000,4) // returns "10,0000,0000" ////////////////////////////////////////////////////////////////////////////////// function script F_InsertComma { - set .@str$, getarg(0); - for (set .@i,getstrlen(.@str$)-3; .@i>0; set .@i,.@i-3) - set .@str$, insertchar(.@str$,",",.@i); + .@value = getarg(0); + .@precision = getarg(1,3); + .@separator$ = getarg( 2,"," ); + + .@str$ = ""+.@value; + .@is_negative = ( .@value < 0 ); + + .@length = getstrlen( .@str$ ) - .@precision - .@is_negative; + while ( .@length > 0 ) { + .@str$ = insertchar( .@str$, .@separator$ , ( .@length + .@is_negative ) ); + .@length -= .@precision; + } return .@str$; } + ////////////////////////////////////////////////////////////////////////////////// // Function that clears job quest variables ////////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3-60-g2f50