Comma Function

A comma function written for FiranMUX that was donated into several code libraries. It will format numbers into a more-legible comma-separated format. For instance, 51234 would become 51,234. The function accounts for both negative and fractional cases when making the legible form of a number.

Author: FiranMUX
Category: Functions
Commands: @create, @describe, @lock, @pemit.

Instructions

Copy and paste the below code into a compatible MUSH or MUX.

MUSHCode for Comma Function

@create Comma Function
@lock Comma Function==me
&U-COMMA Comma Function=switch(1, gt(strlen(%0), 3), [u(u-comma, left(%0, sub(strlen(%0), 3)))]\,[right(%0, 3)], neq(strlen(%0), 0), %0)
&FUNCTION-COMMA Comma Function=switch(1, and(or(strmatch(%0,-*), strmatch(%0,+*)), isnum(%0)), [left(%0,1)][u(me/u-comma, before(trim(abs(%0)), .))][switch(abs(%0), *.*, .[after(trim(abs(%0)), .)])], isnum(%0), [u(me/u-comma, before(trim(%0), .))][switch(%0, *.*, .[after(trim(%0), .)])], #-1 FUNCTION COMMA EXPECTS A NUMBER)
&CMD-COMMATEST Comma Function=$commatest *:@pemit %#=Formatted with commas, %0 would be [u(me/function-comma,%0)]
@Desc Comma Function=A comma function written for FiranMUX that was donated into several code libraries. Type 'commatest <number>' to see how it will format numbers into a more-legible comma-separated format. For instance, 51234 would become 51,234. The function accounts for both negative and fractional cases when making the legible form of a number.