1

I have a string that represents a number 2.882.956.766.235.065,23.

I would like it to convert to 2882956766235065.23 but for string with a shorter length everything is fine, with strings of the same length or longer the part after 16 characters is cut off like this 2882956766235065

I'm working with vue3 and typescript

this is my method

export function convertToNumber(value: number | string) {  
    return Number(String(value).replaceAll('.', '').replaceAll(',', '.'));
}
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • For a floating point number that large you would need to use the built-in BigInt type and massage the floating point value yourself. Thankfully there's already an open-source class written to do this for you named `BigDecimal`. See the duplicate for more information. – Rory McCrossan Jul 28 '23 at 10:10

0 Answers0