In comp.lang.javascript message <VuCdna1-2I7_NaLb4p2dnA@giganews.com>,
The SCORM 2004 spec wants the data type I'm needing to send to be
calculated as a number between 1.0 and -1.0 and then converted to a
string before it is sent. The format required is either a leading 1
(followed by a decimal point and then a 0 i.e. "1.0") or a 0 followed
by a decimal point and then 1 or more digits eg. "0.875". [Though it
doesn't state if 0 should be 0.0 or just 0.]
If you've quoted it adequately, it does so state; the first character
(disregarding sign) must be 0 or 1, then there must be a point, then at
least one digit.
Convert it to a String, check indexOf('.'). If it is 0, then add the
leading 0, if it is 1 then all is fine. If it is 2 then....
Eh?
The following will take any possible Number (AFAICS), including NaN and
Infinities, and output it in a sensible form with a decimal point where
possible. It assumes Number.toString is ECMA-compliant or better.
Str = String(Num).replace(/^(-?\d+)$/, "$1.0")
If the OP's code, at whatever stage of development, should happen to
generate a Number of magnitude greater than 1.0, it's probably desirable
that the transformation should not add confusion by doing further
damage.
StrS(Num, 1, 1), via the FAQ, would do it, with a simpler Sign function;
but that's overkill unless needed otherwise. But the application may be
such that 1/7 should be presented as, say, "0.143" rather than
"0.14285714285714285".