X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.spreadsheet.graph%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fgraph%2Fformula%2FRoundupFormulaFunction.java;fp=bundles%2Forg.simantics.spreadsheet.graph%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fgraph%2Fformula%2FRoundupFormulaFunction.java;h=20c057a8952bebf086ea7f07ee1a8924ee782aae;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=71d88e3e6bf0bae7209501284578195afd8ef8b2;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/RoundupFormulaFunction.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/RoundupFormulaFunction.java index 71d88e3e6..20c057a89 100644 --- a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/RoundupFormulaFunction.java +++ b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/formula/RoundupFormulaFunction.java @@ -1,31 +1,31 @@ -package org.simantics.spreadsheet.graph.formula; - -import org.simantics.spreadsheet.graph.CellFormulaFunction; -import org.simantics.spreadsheet.graph.CellValueVisitor; -import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils; -import org.simantics.spreadsheet.graph.parser.ast.AstArgList; - -public class RoundupFormulaFunction implements CellFormulaFunction { - - @Override - public Object evaluate(CellValueVisitor visitor, AstArgList args) { - if (args.values.size() != 2) throw new IllegalStateException(); - - Object number = args.values.get(0).accept(visitor); - Object digits = args.values.get(1).accept(visitor); - - FormulaError2 err1 = FormulaError2.forObject(number); - if(err1!=null) return err1.getString(); - FormulaError2 err2 = FormulaError2.forObject(digits); - if(err2!=null) return err2.getString(); - - double n = SpreadsheetGraphUtils.asNumber(number); - double n2 = SpreadsheetGraphUtils.asNumber(digits); - - Double scale = Math.pow(10, n2); - - double l = Math.ceil(scale * n); - Double d = Double.valueOf(l / scale); - return d; - } -} +package org.simantics.spreadsheet.graph.formula; + +import org.simantics.spreadsheet.graph.CellFormulaFunction; +import org.simantics.spreadsheet.graph.CellValueVisitor; +import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils; +import org.simantics.spreadsheet.graph.parser.ast.AstArgList; + +public class RoundupFormulaFunction implements CellFormulaFunction { + + @Override + public Object evaluate(CellValueVisitor visitor, AstArgList args) { + if (args.values.size() != 2) throw new IllegalStateException(); + + Object number = args.values.get(0).accept(visitor); + Object digits = args.values.get(1).accept(visitor); + + FormulaError2 err1 = FormulaError2.forObject(number); + if(err1!=null) return err1.getString(); + FormulaError2 err2 = FormulaError2.forObject(digits); + if(err2!=null) return err2.getString(); + + double n = SpreadsheetGraphUtils.asNumber(number); + double n2 = SpreadsheetGraphUtils.asNumber(digits); + + Double scale = Math.pow(10, n2); + + double l = Math.ceil(scale * n); + Double d = Double.valueOf(l / scale); + return d; + } +}