Hi Robert,
Thank you for your feedback and fosdem report ! PostgreSQL
Regards,
omar wrote:And we have to move on so pretty soon I will be taking down http://www.visualfoxpro.com.
ROCLASI wrote:Interesting discussion
Here is a slightly cleaner version of that function:
- Code: Select all
function round(_nValue, _nPrecision) {
var _nAbsValue = Math.abs(_nValue),
_nDivision = Math.pow(10, _nPrecision);
return (Math.round(_nAbsValue * _nDivision) / _nDivision) * (_nValue / _nAbsValue);
}
Or if you really wanted to as the (in)famous Oneliner :
- Code: Select all
function round(_nValue, _nPrecision) {
return (Math.round(Math.abs(_nValue) * Math.pow(10, _nPrecision)) / Math.pow(10, _nPrecision)) * (_nValue / Math.abs(_nValue));
}
function number_roundToTwo(numberToRound) {
// http://stackoverflow.com/questions/11832914/round-to-at-most-2-decimal-places-in-javascript
// Answer of mrkschan seems to be the best, as toFixed() converts to a string which we do not want
return Math.round((numberToRound + 0.00000001) * 100) / 100;
}
Number(Math.round(4.725+'e2')+'e-2')
function round(value, decimals) {
result = Number(Math.round(Math.abs(value)+'e'+decimals)+'e-'+decimals)
if (value<0) {return result*-1} else {return result}
}
function roundValue(value, decimals) {
// sadly PostgreSQL doesn't allow type modifiers to be placeholders so we must concatenate this in the string :(
var _ds = databaseManager.getDataSetByQuery("myConnection", "SELECT CAST(? AS NUMERIC(15," + decimals + "))", [value], -1);
if (_ds.getException()) {
throw _ds.getException();
}
return _ds.getValue(1, 1);
// NOTE: adjust your datatype casting to match your vendors datatypes (numeric vs number, etc.)
}
Number(Math.round(4.725+'e2')+'e-2').toString()
jcompagner wrote:Rounding is kind of formatting, so it is something "to display";
lwjwillemsen wrote:We use our own rounding function throughout our whole Servoy application where rounding is needed, for example rounding to euro cents.
Just counted: used > 2000 times in our code...
jcompagner wrote:i guess the best thing is to store just "cents" in the database...
Not "euros,cents"
Return to Programming with Servoy
Users browsing this forum: No registered users and 13 guests