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