Neobook Tip: Fract Int Sign - Decompose Number Into Its Parts

Contributed by Sam Cox:

This subroutine decomposes a numeric value into useful parts: [Sign], [Int], and [Fract] such that Math "[Sign]*([Int]+[Fract])" "" "[Value]" recreates the original value.
USAGE

SetVar "[Args]" "Value,Decimals"
Gosub "FractIntSign"

The "Decimals" parameters is optional and defaults to "9". To use the default, the usage is:

USAGE WITH DEFAULT VALUE OF DECIMALS

SetVar "[Args]" "Value"
Gosub "FractIntSign"

CODE

:FractIntSign
StrParse "[Args]" "," "[Arg]" "[Argc]"
If "[Argc]" "=" "1"
SetVar "[Arg2]" "9"
Endif
If "[Arg1]" "<" "0"
SetVar "[Sign]" "-1"
Math "Abs([Arg1])" "9" "[Arg1]"
Else
SetVar "[Sign]" "1"
Endif
Math "[Arg1]-0.499999999999999" "0" "[Int]"
Math "[Arg1]-[Int]" "[Arg2]" "[Fract]"
Return