Get Decimal Places
Returns the number of decimal places represented by a number or numeric string.
getDecimalPlaces
The getDecimalPlaces function returns the number of decimal places represented by a given number or numeric string.
Function Signature
function getDecimalPlaces(value: Numeric): numberParameters
value(Numeric): The number or numeric string for which to calculate the number of decimal places.
Return Value
number: The number of decimal places represented by the input value.
Throws
TypeError: If the input value cannot be converted to a number (e.g.,undefined,null,NaN, or invalid numeric strings like'11x').
Example Usage
playground.ts
Notes
- If a numeric string in scientific notation (e.g.,
'1e-6') is provided, it calculates the decimal places accordingly. - If a numeric string has trailing zeros (e.g.,
'1.00'or'9.900'), it is first normalized usingnormalizeNumber, which strips trailing decimal zeros. Thus,'1.00'normalized to1returns0, and'9.900'normalized to9.9returns1. - If a number is an integer, it returns
0. - Internally uses
normalizeNumberto normalize the input value.
Aliases
The following alias can be used for the getDecimalPlaces function:
decimalPlaces
See Also
normalizeNumber- Normalizes a number or numeric string.roundNumber- Rounds a number to a specified number of decimal places.safeAdd- Adds numbers safely, avoiding common floating-point arithmetic issues.
Last updated: Tue, Jun 16, 2026 07:49:37PM (UTC)
