Created
March 24, 2024 12:08
-
-
Save ahallora/8c70899e05a9662ae0399bc72bea6d88 to your computer and use it in GitHub Desktop.
Decimal string to cento number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const decimalStringToCento = (decimalString: string): number => { | |
// Replace comma with dot to make it a valid float | |
const cleanedString = decimalString.replace(",", "."); | |
// Parse the string as a floating-point number | |
const floatValue = parseFloat(cleanedString); | |
// Multiply by 100 to get the cento number | |
const centoNumber = Math.round(floatValue * 100); | |
return centoNumber; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment