Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Functions

  • NumberFormatter(num: string | number, numberConfig?: numberConfigType): any
  • This function is used as a Wrapper around number (Handle every case currently used in Groww Web Project).

    remarks

    numberConfig properties

    • addCommas => Whether you need commas in your number
    • millionCommas => Used for US-stocks commas
    • fallback => Fallback if the backend fails and we are getting null or undefined or isNaN true or Infinite number (Default is 'NA')
    • toFixedValue => Very well explanatory , eg. 10 = 10.00
    • formatToLakhCrore => It will convert to lakhs and crore accordingly with no currency sign
    • formatToBillionTrillion => It will convert to million,billion trillion , specific to US-stocks
    • decimals => Used in lakhs and crore, can be used further for other categories also
    • isCurrency => Specify 'true' for currency format, only use for currency formatting, no other use
    • currency => Default is 'INR', specify USD for US-stocks
    • absoluteValue => Absolute value of the number eg. -10 = 10
    • roundValue => Rounding off of a number eg. 83.56 = 84
    • withSign => This will return string with sign of the number, eg. '+21.34'
    • spaceBetweenSignValue => if you need +3.54 then it should be false, if you need '+ 3.54' , make it true, applicable only when withSign is true
    • formatPaisaToRupee => Converting number from paisa to rupee
    • formatRupeeToPaisa => Converting number from rupee to paisa
    • plainNumber => Converting only to number

    defaultNumberConfig = {
    addCommas:
    true
    millionCommas:
    false
    fallback:
    'NA'
    toFixedValue:
    2
    formatToLakhCrore:
    false
    formatToBillionTrillion:
    false
    decimals:
    2
    isCurrency:
    false
    currency:
    'INR'
    absoluteValue:
    false
    roundValue:
    false
    withSign:
    false
    spaceBetweenSignValue:
    false
    formatPaisaToRupee:
    false
    formatRupeeToPaisa:
    false
    plainNumber:
    false
    };
    example
    NumberFormatter(100023); // '1,00,023.00'
    NumberFormatter(100023,PRICE_CURRENCY); // '₹1,00,023.00'
    NumberFormatter(100023,PRICE_CURRENCY_TO_FIXED_ZERO); // '₹1,00,023'
    NumberFormatter(2869610500000,CONVERT_TO_BILLION_TRILLION); // '2.87T'
    NumberFormatter(100023,PRICE_CURRENCY_FALLBACK_ZERO); // '₹1,00,023.00' (If anything fails then fallback used as '₹0')
    NumberFormatter(100023,PRICE_CURRENCY_USD); // '$100,023.00'
    NumberFormatter(100023,CURRENCY_CONVERT_TO_RUPEE); // '₹1,000.23' (First it will convert from paisa to rupee and then to currency)
    NumberFormatter(31490000000,CONVERT_TO_LAKH_CRORE); // '3149.00Cr'
    NumberFormatter(100023, {
    ...PRICE_CURRENCY,
    withSign: true
    }); // '+₹1,00,023.00' (It will give you sign also with the currency formatting)
    NumberFormatter(100023, {
    ...PRICE_CURRENCY,
    withSign: true,
    spaceBetweenSignValue
    }); // '+ ₹1,00,023.00' (It will give you sign also (with space between value and sign) with the currency formatting)

    Parameters

    • num: string | number
    • numberConfig: numberConfigType = {}

    Returns any

  • addingCommasToNumber(x: string | number): string
  • This method can be used to add commas as per Indian system to any valid number of type string or number.

    remarks

    It's strongly recommended to pass number only but method can also handle valid string.

    example
    addingCommasToNumber(1)); // 1
    addingCommasToNumber(11)); // 11
    addingCommasToNumber(111)); // 111
    addingCommasToNumber('-1111')); // -1,111
    addingCommasToNumber('11111')); // 11,111
    addingCommasToNumber(-111111)); // -1,11,111

    Parameters

    • x: string | number

      Number that you want to be formatted with commas as per Indian system

    Returns string

  • changeFormatToLakhCrore(num: string | number, toFixedDecimals?: number): string | number
  • This method can be used to convert the number in lakhs and crore format.

    remarks

    It returns the number as it is on error ,empty string, null, undefined, NaN is passed.

    example
    changeFormatToLakhCrore(103213456); // 10.32Cr
    changeFormatToLakhCrore('1034564'); // 10.35L
    changeFormatToLakhCrore('1027654',3); // 10.277L

    Parameters

    • num: string | number
    • toFixedDecimals: number = 2

    Returns string | number

  • convertPaisaToRupee(value: number): number
  • This method can be used to convert paisa to rupees

    remarks

    Paise cannot be in decimal, so make sure you pass integer else it will return argument only without any change

    example
    convertPaisaToRupee(100)); // 1
    

    Parameters

    • value: number

      Number that you want to be converted to rupee

    Returns number

  • convertRupeeToPaisa(value: number): number
  • This method can be used to convert rupees to paisa

    example
    convertRupeeToPaisa(1)); // 100
    

    Parameters

    • value: number

      Number that you want to be converted to paise

    Returns number

  • convertToBillionTrillionFormat(num: string | number, toFixedDecimals?: number): string | number
  • This method can be used to convert the number in thousand,million,billion and trillion format.

    remarks

    It returns the number as it is on error ,empty string, null, undefined, NaN is passed.

    example
    convertToBillionTrillionFormat(3098100000); // 3.09B
    convertToBillionTrillionFormat(2849537600000); // 2.84T
    convertToBillionTrillionFormat(12200000); // 12.20M
    convertToBillionTrillionFormat(100232332,3); // 100.232M
    convertToBillionTrillionFormat('100232332'); // 100.23M

    Parameters

    • num: string | number
    • toFixedDecimals: number = 2

    Returns string | number

  • getIntegerRandomNoBetweenTwoNo(min: number, max: number): number
  • This method can be used to get a random integer number between 2 number both inclusive.

    example
    getIntegerRandomNoBetweenTwoNo(0,500)); // will return anything between 0 to 500
    

    Parameters

    • min: number

      Starting number

    • max: number

      Ending number

    Returns number

  • getNumberSign(num: string | number): "" | "-" | "+"
  • This method can be used to give the sign of the number : + , - or empty if 0.

    remarks

    It returns empty (No sign) for 0 value.

    example
    getNumberSign(1000); // '+'
    getNumberSign('1200'); // '+'
    getNumberSign(-12430); // '-'
    getNumberSign(0); // ''

    Parameters

    • num: string | number

      Number that you want to get sign for.

    Returns "" | "-" | "+"

  • isValidMobileNumber(mobNumber: string | number): boolean
  • This method can be used to validate 10 digit mobile number.

    remarks

    It's strongly recommended to pass number only but method can also handle valid string.

    example
    isValidMobileNumber(1234567890) // true
    isValidMobileNumber(-1234567890) // false
    isValidMobileNumber(123) // false
    isValidMobileNumber("123") // false
    isValidMobileNumber("1234567890") // true
    isValidMobileNumber("-1234567890") // false

    Parameters

    • mobNumber: string | number

      Mobile number that you want to validate

    Returns boolean

  • millionWithCommas(num: string | number): string | number
  • This method can be used to add commas as per million format (thousands separator).

    remarks

    It returns the number as it is on error

    example
    millionWithCommas(1030120313); // 1,030,120,313
    millionWithCommas(1000001); // 1,000,001
    millionWithCommas(1000001.12432432); // 1,000,001.12432432

    Parameters

    • num: string | number

      Number that you want to be formatted with commas

    Returns string | number

  • ordinalSuffixOfNumber(num: number): string
  • This method can be used to find ordinal suffix of any number.

    example
    ordinalSuffixOfNumber(1); // 1st
    ordinalSuffixOfNumber(11); // 11th
    ordinalSuffixOfNumber(21); // 21st
    ordinalSuffixOfNumber(101); // 103rd

    Parameters

    • num: number

      Number that you want to find ordinal suffix of

    Returns string

  • toFixedWithoutRounding(num: string | number, toFixedDecimal: number): string | number
  • This method fixes the decimal part but without round off the value.

    example
    toFixedWithoutRounding(1.56789,4) => 1.5678
    

    Parameters

    • num: string | number

      number entered in input element

    • toFixedDecimal: number

      Number of decimal places you want to fix the decimal part to.

    Returns string | number

Generated using TypeDoc