stu:

Feel the need to dig for this topic again... In the past I stick to my primitive code to display thousand separator... I'm still looking for a code efficient way of adding thousand separator to int values. And I'm not talking about currency, just any number...

(?) any ideas or custom plugin? Hell, I'll pay for it.

I'm still looking for a code efficient way of adding thousand separator to int values. And I'm not talking about currency, just any number

A bit more complicated if numbers can also be negative .... but for now, assume they are (unsigned) positive (or zero)

So, your numbers could be ...

a) less than 1,000 (length less than 4)

0 ==> 0

7 ==> 7

34 ==> 34

555 ==> 555

b) 1,000 to 9,999 (length of 4)

1234 ==> 1,234

c) 10,000 to 99,999 (length of 5)

56789 ==> 56,789

d) 100,000 to 999,999 (length of 6)

223344 ==> 223,344

e) 1,000,000 to 9,999,999 (length of 7)

1998877 ==> 1,998,877

f) 10,000,000 to 99,999,999 (length of 8 )

41998877 ==> 41,998,877

g) 100,000,000 to 999,999,999 (length of 9)

641998877 ==> 641,998,877

h) 1,000,000,000 to 9,999,999,999 (length of 10)

3641998877 ==> 3,641,998,877

... etc. etc. up to the highest number you wish to support

So, you would take actions depending on the length of the integer number (make sure you are not tripped up by leading zeroes like 00123)

Say, the integer value is in [myInteger] ...

- Code: Select all
`SetVar [ThousandSeparator]" "!,"`

GoSub "InsertThousandSeparator"

... and subroutine would be ...

- Code: Select all
`:InsertThousandSeparator`

StrLen "[myInteger]" "[IntegerSize]"

If "[IntegerSize]" "<" "4"

Setvar "[myString]" "[myInteger]"

Return

EndIf

If "[IntegerSize]" "=" "4"

StrIns "[ThousandSeparator]" "[myInteger]" "2" "[myString]"

Return

EndIf

If "[IntegerSize]" "=" "5"

StrIns "[ThousandSeparator]" "[myInteger]" "3" "[myString]"

Return

EndIf

If "[IntegerSize]" "=" "6"

StrIns "[ThousandSeparator]" "[myInteger]" "4" "[myString]"

Return

EndIf

If "[IntegerSize]" "=" "7"

StrIns "[ThousandSeparator]" "[myInteger]" "5" "[tempString]"

StrIns "[ThousandSeparator]" "[tempString]" "2" "[myString]"

Return

EndIf

If "[IntegerSize]" "=" "8"

StrIns "[ThousandSeparator]" "[myInteger]" "6" "[tempString]"

StrIns "[ThousandSeparator]" "[tempString]" "3" "[myString]"

Return

EndIf

If "[IntegerSize]" "=" "9"

StrIns "[ThousandSeparator]" "[myInteger]" "7" "[tempString]"

StrIns "[ThousandSeparator]" "[tempString]" "4" "[myString]"

Return

EndIf

If "[IntegerSize]" "=" "10"

StrIns "[ThousandSeparator]" "[myInteger]" "8" "[tempString]"

StrIns "[ThousandSeparator]" "[tempString]" "5" "[temptring]"

StrIns "[ThousandSeparator]" "[tempString]" "2" "[myString]"

Return

EndIf

SetVar "[myString]" "****"

Return