|
Last change
on this file since a762898 was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago |
|
Prototype 1.1
|
-
Property mode
set to
100644
|
|
File size:
669 bytes
|
| Line | |
|---|
| 1 | import {formatDecimalParts} from "./formatDecimal.js";
|
|---|
| 2 |
|
|---|
| 3 | export var prefixExponent;
|
|---|
| 4 |
|
|---|
| 5 | export default function(x, p) {
|
|---|
| 6 | var d = formatDecimalParts(x, p);
|
|---|
| 7 | if (!d) return prefixExponent = undefined, x.toPrecision(p);
|
|---|
| 8 | var coefficient = d[0],
|
|---|
| 9 | exponent = d[1],
|
|---|
| 10 | i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
|
|---|
| 11 | n = coefficient.length;
|
|---|
| 12 | return i === n ? coefficient
|
|---|
| 13 | : i > n ? coefficient + new Array(i - n + 1).join("0")
|
|---|
| 14 | : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
|
|---|
| 15 | : "0." + new Array(1 - i).join("0") + formatDecimalParts(x, Math.max(0, p + i - 1))[0]; // less than 1y!
|
|---|
| 16 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.