UNPKG

@synotech/utils

Version:

a collection of utilities for internal use

22 lines (21 loc) 700 B
/** * This method validates email address * @module currencyParse * @param {String} number the number or string instance to parse as a floating currency string * @return {string} {String} a boolean value indicating if the email is valid or not * @example * * currencyParse('123.43') // return '123.43' * currencyParse('12xs3.3') // return '123.30' * */ export function currencyParse(number: string | number): string { try { number = number.toString(); const regex = /[^0-9\.\|]+/; number = parseFloat(number.split(regex).join('')); return parseFloat(number.toString()).toFixed(2).toString(); } catch (error) { return parseFloat(number.toString()).toFixed(2).toString(); } }