ts-utils
  • Getting Started
  • Contributing
  • Testing
  • Functions
    • Array Methods
      • isArr
      • isArrEmpty
      • pushUniqueValue
      • pushOrUpdate
    • Date Methods
      • toNow
      • formatDate
      • fromNow
    • Number Methods
      • toFixed
      • parseNumber
      • parseFormat
      • addUnit
      • addSeparators
      • formatNumber
      • ensureNumber
      • numberEmptyState
    • Object Methods
      • parseJSON
      • deepClone
      • parseNumValues
      • removeEmptyKeys
      • sanitizeQuery
      • removeKeys
      • renameKey
      • renameKeys
      • sortByKeyLength
      • querylize
      • parseNumericObj
      • reserveKeys
      • hasKeysAndValues
    • String Methods
      • randomStr
      • toUpperCase
      • toLowerCase
      • toFullUrl
      • initials
      • generateUuid
Powered by GitBook
On this page
  • parseNumber(num)
  • Arguments
  • Returns
  • Example
  • Usage
  • Notes

Was this helpful?

  1. Functions
  2. Number Methods

parseNumber

parseNumber(num)

Parses the input number or string and returns an object containing the float, integer, and sign components of the number. It provides a structured breakdown of the numeric value for further processing or analysis.

Arguments

  • num (string | number): The input number or string to parse.

Returns

  • (object): An object containing the following properties:

    • float (number): The absolute value of the parsed float.

    • int (number): The absolute value of the parsed integer.

    • sign (string): The sign of the number as a string ("-" for negative numbers, "" for positive or zero).

Example

typescript
import { parseNumber } from 'check-engineering/ts-utils';

const numberString = "-3.14";
const parsedNumber = parseNumber(numberString); // => { float: 3.14, int: 3, sign: "-" }

Usage

typescript
import { parseNumber } from 'check-engineering/ts-utils';

const number = 42;
const parsedNumber = parseNumber(number); // => { float: 42, int: 42, sign: "" }

Notes

  • The parseNumber function extracts the float, integer, and sign components of the input number for further analysis or processing.

  • It provides a structured representation of the numeric value, allowing for detailed examination of its components.

  • The function returns an object with the absolute float and integer values, along with the sign of the number as a string.

PrevioustoFixedNextparseFormat

Last updated 11 months ago

Was this helpful?