1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00

roundExponential: add docstring, remove unnecessary cast

This commit is contained in:
Erik Marks 2020-09-08 21:28:24 -07:00
parent d532cdc459
commit c5917aa445

View File

@ -121,11 +121,17 @@ export function hasUnconfirmedTransactions (state) {
return unconfirmedTransactionsCountSelector(state) > 0
}
export function roundExponential (value) {
const stringValue = String(value)
/**
* Rounds the given decimal string to 4 significant digits.
*
* @param {string} decimalString - The base-ten number to round.
* @returns {string} The rounded number, or the original number if no
* rounding was necessary.
*/
export function roundExponential (decimalString) {
const PRECISION = 4
const bigNumberValue = new BigNumber(stringValue)
const bigNumberValue = new BigNumber(decimalString)
// In JS, numbers with exponentials greater than 20 get displayed as an exponential.
return bigNumberValue.e > 20 ? bigNumberValue.toPrecision(PRECISION) : stringValue
return bigNumberValue.e > 20 ? bigNumberValue.toPrecision(PRECISION) : decimalString
}