Mathematical rounding should always be correct in my opinion
That's the book all about:
A computer can not do true mathematical rounding due to the representation of numbers in a series of bits / bytes.
Mathematical rounding should always be correct in my opinion
lwjwillemsen wrote:Mathematical rounding should always be correct in my opinion
That's the book all about:
A computer can not do true mathematical rounding due to the representation of numbers in a series of bits / bytes.
/**
* Round using exponential notation shifting
*
* @param {Number} value
* @param {Number} precision
*/
function round(value, precision) {
return Number(Math.round(Number(Math.abs(value)+'e'+precision))+'e-'+precision) * (value < 0 ? -1 : 1)
}
omar wrote:
- Code: Select all
/**
* Round using exponential notation shifting
*
* @param {Number} value
* @param {Number} precision
*/
function round(value, precision) {
return Number(Math.round(Number(Math.abs(value)+'e'+precision))+'e-'+precision) * (value < 0 ? -1 : 1)
}
/**
* Round using exponential notation shifting
*
* @param {Number} value
* @param {Number} precision
*/
function round(value, precision) {
return Number(Math.round(Number(Math.abs(value)+'e'+precision))+'e-'+precision) * (value < 0 ? -1 : 1)
}
function core_round_money(vValue) {
if(vValue<0) {
return Math.round((vValue - 0.00000001) * 100) / 100;
} else {
return Math.round((vValue + 0.00000001) * 100) / 100;
}
}
/**
* Round using exponential notation shifting
*
* @param {Number} value
* @param {Number} precision
*/
function round(value, precision) {
return Number(Math.round(Number(Math.abs(value)+'e'+precision))+'e-'+precision) * (value < 0 ? -1 : 1)
}
function core_round_money(vValue) {
if(vValue<0) {
return Math.round((vValue - 0.00000001) * 100) / 100;
} else {
return Math.round((vValue + 0.00000001) * 100) / 100;
}
}
/**
* @param {Number} value
* @param {Number} precision
*/
function roundNumber(value, precision ) {
return Math.round( (value + (value < 0 ? -0.00000001 : 0.00000001)) * Math.pow(10, precision)) / Math.pow(10, precision);
}
function roundNumber(value,precision){return Math.round((value+(value<0?-1e-8:1e-8))*Math.pow(10,precision))/Math.pow(10,precision)}
Return to Programming with Servoy
Users browsing this forum: Harjo and 4 guests