| 96 | return { signed, width, decimals, name }; |
| 97 | } |
| 98 | function toString(val, decimals) { |
| 99 | let negative = ""; |
| 100 | if (val < BN_0) { |
| 101 | negative = "-"; |
| 102 | val *= BN_N1; |
| 103 | } |
| 104 | let str = val.toString(); |
| 105 | // No decimal point for whole values |
| 106 | if (decimals === 0) { |
| 107 | return (negative + str); |
| 108 | } |
| 109 | // Pad out to the whole component (including a whole digit) |
| 110 | while (str.length <= decimals) { |
| 111 | str = Zeros + str; |
| 112 | } |
| 113 | // Insert the decimal point |
| 114 | const index = str.length - decimals; |
| 115 | str = str.substring(0, index) + "." + str.substring(index); |
| 116 | // Trim the whole component (leaving at least one 0) |
| 117 | while (str[0] === "0" && str[1] !== ".") { |
| 118 | str = str.substring(1); |
| 119 | } |
| 120 | // Trim the decimal component (leaving at least one 0) |
| 121 | while (str[str.length - 1] === "0" && str[str.length - 2] !== ".") { |
| 122 | str = str.substring(0, str.length - 1); |
| 123 | } |
| 124 | return (negative + str); |
| 125 | } |
| 126 | /** |
| 127 | * A FixedNumber represents a value over its [[FixedFormat]] |
| 128 | * arithmetic field. |