FdaFunction.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction(
"FDA", 1, 2, {
description : "对value进行四舍六入五留双修约,保留小数点后指定位数",
parameters : [ {
name : "value",
repeatable : false,
optional : false
}, {
name : "places",
repeatable : false,
optional : false
} ]
});
FdaFunction.prototype.evaluate = function(context, value, places) {
var num;
if (!isNaN(parseInt(value)) && !isNaN(parseInt(places))) {
var viewport = designer.wrapper.spread.getActiveSheet().getFormatter(context.row,context.col,GC.Spread.Sheets.SheetArea.viewport);
if(isEmpty(viewport)){
designer.wrapper.spread.getActiveSheet().setFormatter(context.row,context.col,"@",GC.Spread.Sheets.SheetArea.viewport);
}
if (value < 0) {
num = -value;
} else {
num = value;
}
if(places<0)
return value;
var v=Number(value);
var s=v+"";
var result="";
if(s.indexOf(".")!=-1){
var s_1=s.substring(s.indexOf(".")+1);
if(s_1.length==parseInt(places)+1){
if(s_1.endsWith("5")){
var s_2=s.substr(0,s.length-1);
var n=Number(s_2);
var s_n=n.toFixed(places);
var x=s_n.substring(s_n.length-1);
if(Number(x)%2==0){
result=s_n;
}
}
}
}
if(result==""){
result=v.toFixed(places);
}
if(value < 0&& value!='0'){
result = "-"+result;
}
return result;
}else{
return "#VALUE!";
}
}
|
-
|