MARX#58496: Handmatige factuur invoer. Btw bedrag in eerste instantie soms onjuist.

svn path=/Website/branches/v2019.1/; revision=43392
This commit is contained in:
Maykel Geerdink
2019-07-17 12:09:40 +00:00
parent 849e252400
commit d090d7d912

View File

@@ -810,11 +810,58 @@ function allowInputExpression(thisObj)
} }
} }
// Afronden van geldbedragen.
// roundcurr(1.275, 2); // Returns 1.28
// roundcurr(-1.275, 2); // Returns -1.28
// roundcurr(1.27499, 2); // Returns 1.27
// roundcurr(-1.27499, 2); // Returns -1.27
// roundcurr(1.2345678e+2, 2); // Returns 123.46
// roundcurr(1234.5678, -2); // Returns 1200
// roundcurr(123.45); // Returns 123
function roundcurr(value, exp) {
if (typeof exp === 'undefined' || +exp === 0)
return Math.round(value);
value = +value;
exp = +exp;
if (isNaN(value) || !(typeof exp === 'number' && exp % 1 === 0))
return NaN;
// Negatieve getallen voor het afronden even positief maken.
var negatief = false;
if (value < 0)
{
negatief = true;
value = value * -1;
}
// Shift
value = value.toString().split('e');
value = Math.round(+(value[0] + 'e' + (value[1]? (+value[1] + exp) : exp)));
// Negatieve getallen weer negatief maken.
if (negatief)
value = value * -1;
// Shift back
value = value.toString().split('e');
value = +(value[0] + 'e' + (value[1]? (+value[1] - exp) : -exp))
return (value).toFixed(exp); // value is al afgerond. ik kan nu gerust toFixed() gebruiken om eind nullen terug te krijgen (1.5toFixed(2) => 1.50).
}
// Voorheen num2curr.js // Voorheen num2curr.js
function num2curr(s) { function num2curr(s) {
// debugger;
if( !isNaN(s) ) { if( !isNaN(s) ) {
s = s.toFixed(2); // MARX#58496: Be careful using ".toFixed()" as it might return different rounding results for different browsers.
//
// Afronding waarde.toFixed(2) voor verschillende browsers:
// IE: 251,075 => 251,08,
// FF,Crome: 251,075 => 251,07)
//
// Therefore we use roundcurr instead.
//s = s.toFixed(2);
s = roundcurr(s, 2);
} }
return s; return s;
} }
@@ -828,7 +875,15 @@ function num2currEditable(fnum, decimals)
if (typeof decimals == "undefined") if (typeof decimals == "undefined")
decimals = 2; decimals = 2;
fnum = fnum.toFixed(decimals); // MARX#58496: Be careful using ".toFixed()" as it might return different rounding results for different browsers.
//
// Afronding waarde.toFixed(2) voor verschillende browsers:
// IE: 251,075 => 251,08,
// FF,Crome: 251,075 => 251,07)
//
// Therefore we use roundcurr instead.
//fnum = fnum.toFixed(decimals);
fnum = roundcurr(fnum, decimals);
var waarde2 = (1.5).toLocaleString(); // Eventueel gewenste komma. var waarde2 = (1.5).toLocaleString(); // Eventueel gewenste komma.
fnum = fnum.substring(0, fnum.length - decimals - 1) + waarde2.substring(2, 1) + fnum.substring(fnum.length - decimals); fnum = fnum.substring(0, fnum.length - decimals - 1) + waarde2.substring(2, 1) + fnum.substring(fnum.length - decimals);