Skip to content

Instantly share code, notes, and snippets.

@ahallora
Created March 24, 2024 12:08
Show Gist options
  • Save ahallora/8c70899e05a9662ae0399bc72bea6d88 to your computer and use it in GitHub Desktop.
Save ahallora/8c70899e05a9662ae0399bc72bea6d88 to your computer and use it in GitHub Desktop.
Decimal string to cento number
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