Wondering if anybody has a snippet in Verse for formatting an int or float to a string with commas in it at the thousand, million mark? Can’t find anything anywhere so far. Wish there was a format function… or is there?
I think you might be looking for this snippet, which got published by a staff member last month
Thanks Fenzy! I passed by that one not thinking it would have what I want. You’re the best!
actually, I looked and it’s not in there. Anything else out there?
So what do you want exactly ? Could you send an expected result example ?
EDIT: I just understood, you just want to have the commas in it
Well I don’t have any snippet but you should be able to just call ToString(:float)
→ Floor[]
to get rid of the decimals → then with a for loop just add the characters one by one, or three by three and plug the commas in if needed
Realized it’s not what you asked for but I trust that you’re able to do this youself
aww man… I wanted somebody to do it for me like everybody asks of me
I’ll see what I can do, if I sort it out then I’ll share here and stick it in snippets too
DotFormatNumber(NumberToFormat : int) : string =
ConvertedString := ToString(NumberToFormat)
var ReturnString : string = ""
for(Index := 0..ConvertedString.Length-1):
if(Mod[ConvertedString.Length - Index, 3] = 0 and Index<> 0):
set ReturnString = ReturnString + ","
if(Char:=ConvertedString[Index]):
set ReturnString = ReturnString + ToString(Char)
return ReturnString