All files order-of-magnitude.ts

100% Statements 4/4
100% Branches 1/1
100% Functions 1/1
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 231x                                     1x 202x 202x  
import { illion } from './illion.ts';
 
/**
 * Get the spelled out word for an exponent
 * @remarks This is only using the exponent, There is no limit to the numbers this function can represents, however Javascript/Typescript can only represent
 * numbers up to 1e308, which limits the numbers that this method can represent to 10 \*\* 10 \*\* 308 which is really really big.
 * @param exponent - The exponent to convert
 * @returns Order of Magnitude as text
 * @example
 * ```typescript
 * orderOfMagnitude(3); // "thousand"
 * orderOfMagnitude(6); // "million"
 * orderOfMagnitude(9); // "billion"
 * orderOfMagnitude(0); // ""
 * orderOfMagnitude(-3); // null
 * ```
 * @group Math
 * @category Verbalization
 */
export function orderOfMagnitude(exponent: number): string | null {
  return illion('000', exponent, false).word;
}