From e43983aefe48119d8c22813e162ccd05f29fc33a Mon Sep 17 00:00:00 2001 From: AnnieRuru Date: Sat, 3 Oct 2020 08:52:51 +0800 Subject: [PATCH] update F_InsertComma to allow numbers bigger than INT_MAX --- npc/other/Global_Functions.txt | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/npc/other/Global_Functions.txt b/npc/other/Global_Functions.txt index 81e511ac2a0..e4e43c98342 100644 --- a/npc/other/Global_Functions.txt +++ b/npc/other/Global_Functions.txt @@ -44,23 +44,17 @@ // 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" +// 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 { - .@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; - } + .@str$ = getarg(0); + .@precision = getarg(1, 3); + .@separator$ = getarg(2, ","); + .@is_negative = (charat(.@str$, 0) == "-"); + for (.@i = getstrlen(.@str$) - .@precision; .@i > .@is_negative; .@i -= .@precision) + .@str$ = insertchar(.@str$, .@separator$, .@i); return .@str$; }