You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Mariusz G <ma...@o2.pl> on 2007/07/17 14:58:37 UTC

function - returns decimal

There is a test function:

create function round(a decimal(31,11), scale integer) returns
decimal(31,11)
parameter style java no sql language java
external name 'derbyextension.Derby.round'; 

Why this function returns decimal(31,31) instead of decimal(31,11)?

ij> values round(0.225,2);
1
---------------------------------
0.2300000000000000000000000000000

1 row selected

ij> values round(1.225,2);
1
---------------------------------
ERROR 22003: Overflow occurred during numeric data type conversion of
"1.23000000000". :


Re: function - returns decimal

Posted by Mariusz G <ma...@o2.pl>.
package derbyextension;

import java.math.*;

public class Derby
{
  public static BigDecimal round(BigDecimal a, int scale)
  {
    return a.setScale(scale, RoundingMode.HALF_UP); 
  }
}

-- 
View this message in context: http://www.nabble.com/function---returns-decimal-tf4099457.html#a11920953
Sent from the Apache Derby Users mailing list archive at Nabble.com.


Re: function - returns decimal

Posted by Julius Stroffek <Ju...@Sun.COM>.
Hi Mariusz,

can you provide the source for derbyextension.Derby class?

Thanks

Julo

Mariusz G wrote:
> There is a test function:
>
> create function round(a decimal(31,11), scale integer) returns
> decimal(31,11)
> parameter style java no sql language java
> external name 'derbyextension.Derby.round'; 
>
> Why this function returns decimal(31,31) instead of decimal(31,11)?
>
> ij> values round(0.225,2);
> 1
> ---------------------------------
> 0.2300000000000000000000000000000
>
> 1 row selected
>
> ij> values round(1.225,2);
> 1
> ---------------------------------
> ERROR 22003: Overflow occurred during numeric data type conversion of
> "1.23000000000". :
>
>