Similar js toExponential method, but returns result in power format, instead of Xe-1 it returns X⋅10⁻¹
Usage example:
console.log(toPower(3, 111)); // out 1.110⋅10²
console.log(toPower(3, 0.00000000000000123)); //out 1.230⋅10⁻¹⁵Similar js toExponential method, but returns result in power format, instead of Xe-1 it returns X⋅10⁻¹
Usage example:
console.log(toPower(3, 111)); // out 1.110⋅10²
console.log(toPower(3, 0.00000000000000123)); //out 1.230⋅10⁻¹⁵| export const toPower = (fractionDigits, value) => ( | |
| ([, num, sign, exp], supNums, supMinus) => | |
| `${num}⋅10${sign && supMinus}${[...exp].map(v => supNums[+v]).join()}` | |
| )( | |
| (/([\d\.]+)e([-]*)[+]*(\d+)/).exec(value.toExponential(fractionDigits)), | |
| ['⁰', '¹', '²', '³', '⁴', '⁵', '⁶', '⁷', '⁸', '⁹'], | |
| '⁻' | |
| ); |