Skip to content

Instantly share code, notes, and snippets.

@micheletolve
Created April 2, 2024 12:41
Show Gist options
  • Save micheletolve/7b55311c04b654065673e61c56b06944 to your computer and use it in GitHub Desktop.
Save micheletolve/7b55311c04b654065673e61c56b06944 to your computer and use it in GitHub Desktop.
/**
* Convert value to the money.
* @param {any} s string with the value
* @param {number} ndd NumberDecimalDigits
* @returns
*/
const toMoney = (s, ndd) => {
let cookieUser = GetLoggedUserInfo();
let cookieCulture;
let culture;
if (cookieUser !== undefined) {
culture = cookieUser.LANGUAGE;
} else {
cookieCulture = GetCookie("culture");
if (cookieCulture !== undefined) {
culture = cookieCulture;
} else {
culture = "en-US";
}
}
let value = Number(parseFloat(s / 100));
return value.toLocaleString(culture, { maximumFractionDigits: parseInt(ndd), minimumFractionDigits: parseInt(ndd) });
}
/**
* Convert millisecond to time
* @param {any} m
* @returns
*/
function millisecondsToTime(m) {
let milliseconds = m % 1000;
let seconds = Math.floor((m / 1000) % 60);
let minutes = Math.floor((m / (60 * 1000)) % 60);
return minutes + " min " + seconds + " sec " + milliseconds + " msec";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment