[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice/kspread/functions
From:       Carlos Licea <carlos_licea () hotmail ! com>
Date:       2010-03-11 3:05:14
Message-ID: 1268276714.083252.30141.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1101837 by clicea:

Fix ROUNDUP() and ROUNDDOWN() functions to behave like it's done in 
OOo. It contradicts OpenFormula but I have 3 reasons for the change:
1)Interoperatibility, OOo and Excel have the market share, we need 
to provide the same behavior whenever is possible.
2)OpenFormula already provides a function that behaves like ROUNDUP 
and ROUNDDOWN behaved: floor and celing (which gives the nearest 
number to the left or to the right of the real line, respectively).
3)OpenFormula follows OOo, the behavior is very likely to change to 
reflect that.



 M  +18 -4     math.cpp  
 M  +8 -6      math.xml  


--- trunk/koffice/kspread/functions/math.cpp #1101836:1101837
@@ -890,16 +890,30 @@
 Value func_rounddown(valVector args, ValueCalc *calc, FuncExtra *)
 {
     if (args.count() == 2)
-        return calc->roundDown(args[0], args[1]);
-    return calc->roundDown(args[0], 0);
+        if (calc->greater(args[0], 0.0))
+            return calc->roundDown(args[0], args[1]);
+        else
+            return calc->roundUp(args[0], args[1]);
+
+    if (calc->greater(args[0], 0.0))
+        return calc->roundDown(args[0], 0);
+    else
+        return calc->roundUp(args[0], 0);
 }
 
 // Function: ROUNDUP
 Value func_roundup(valVector args, ValueCalc *calc, FuncExtra *)
 {
     if (args.count() == 2)
-        return calc->roundUp(args[0], args[1]);
-    return calc->roundUp(args[0], 0);
+        if (calc->greater(args[0], 0.0))
+            return calc->roundUp(args[0], args[1]);
+        else
+            return calc->roundDown(args[0], args[1]);
+
+    if (calc->greater(args[0], 0.0))
+        return calc->roundUp(args[0], 0);
+    else
+        return calc->roundDown(args[0], 0);
 }
 
 // Function: ROUND
--- trunk/koffice/kspread/functions/math.xml #1101836:1101837
@@ -1128,11 +1128,12 @@
 	<Type>Int</Type>
       </Parameter>
       <Help>
-	<Text>The ROUNDUP(value;[digits]) function returns value rounded up. Digits is the \
number of digits to which you want to round that number. If digits is zero or \
omitted, value is rounded up to the nearest integer.</Text> +	<Text>The \
ROUNDUP(value;[digits]) function returns value rounded so that its absolute value is \
greater. Digits is the number of digits to which you want to round that number. If \
digits is zero or omitted, value is rounded up to the nearest integer.</Text>  \
<Syntax>ROUNDUP(value;[digits])</Syntax> +	<Example>ROUNDUP(1.252) equals 2</Example>
 	<Example>ROUNDUP(1.252;2) equals 1.26</Example>
-	<Example>ROUNDUP(-1.252;2) equals -1.25</Example>
-	<Example>ROUNDUP(-1.252) equals -1</Example>
+	<Example>ROUNDUP(-1.252;2) equals -1.26</Example>
+	<Example>ROUNDUP(-1.252) equals -2</Example>
 	<Related>ROUND</Related>
 	<Related>ROUNDDOWN</Related>
       </Help>
@@ -1150,11 +1151,12 @@
 	<Type>Int</Type>
       </Parameter>
       <Help>
-	<Text>The ROUNDDOWN(value;[digits]) function returns value rounded down. Digits is \
the number of digits to which you want to round that number. If digits is zero or \
omitted, value is rounded down to the nearest integer.</Text> +	<Text>The \
ROUNDDOWN(value;[digits]) function returns value rounded so that its absolute value \
is lesser. Digits is the number of digits to which you want to round that number. If \
digits is zero or omitted, value is rounded down to the nearest integer.</Text>  \
<Syntax>ROUNDDOWN(value;[digits])</Syntax> +    <Example>ROUNDDOWN(1.252) equals \
1</Example>  <Example>ROUNDDOWN(1.252;2) equals 1.25</Example>
-	<Example>ROUNDDOWN(-1.252;2) equals -1.26</Example>
-	<Example>ROUNDDOWN(-1.252) equals -2</Example>
+	<Example>ROUNDDOWN(-1.252;2) equals -1.25</Example>
+	<Example>ROUNDDOWN(-1.252) equals -1</Example>
 	<Related>ROUND</Related>
 	<Related>ROUNDUP</Related>
       </Help>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic