Tuesday, January 3, 2023

ToString.FromNum

ToString.FromNum

abstract operation

  1. If m is NaN, return the String "NaN".
  2. If m is +0 or -0, return the String "0".
  3. If m is less than zero, return the String concatenation of the String "-" and ToString(-m).
  4. If m is infinity, return the String "Infinity".
  5. let n, k, and s be integers such that k >= 1, s in [10^(k-1), 10^k), the Number value for s * 10^(n-k) is m. Note that k is the number of digits in the decimal representation of s, that s is not divisible by 10.
  6. if both k and n are no greater than 21:
    • if k is no greater than n, return the string-concatenation of:
      • the k digits of the decimal representation of s
      • n−k occurrences of the character 0
    • if n is greater than 0, return the string-concatenation of:
      • the code units of the most significant n digits of the decimal representation of s
      • the code unit 0x002E (FULL STOP)
      • the code units of the remaining k - n digits of the decimal representation of s
  7. ...

example 0.12300

k=3, s=123, n=0

example 123.4

n=k1=3, k2=1, s=123.4

example 0.0423

k=3, s=423, n=-1 ==> k1=n=-1,pow(10,k1-1)=0.04

example 42300

k=3, s=423, n=5 ==> pow(10, n-1) = 4

No comments:

Post a Comment