Skip to content

Instantly share code, notes, and snippets.

@CuzImBisonratte
Last active January 26, 2022 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CuzImBisonratte/435ed58f330bac365039b05cde9351d8 to your computer and use it in GitHub Desktop.
Save CuzImBisonratte/435ed58f330bac365039b05cde9351d8 to your computer and use it in GitHub Desktop.
// Function to format the time
function formatTime(number) {
// If the number is not 2 digits, add a 0 in front
if (number.toString().length <= 1) {
// Add a 0 in front
number = "0" + number;
}
// return the formatted number
return number;
}
// Function to format a number with dots as thousands separator
function formatNumber(number) {
// Replace the decimal point
var numberNew = number.toString().split(".")[0].replace(/\B(?=(\d{3})+(?!\d))/g, ".");
// replace english point with german comma
if (number.toString().split(".")[1] != undefined) {
numberNew = numberNew + "," + number.toString().split(".")[1];
}
// return the formatted number
return numberNew;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment