|
|
|
|
|
|
|
|
|
|
|
Re: Next multiple of 10 value for the given integer [message #595368 is a reply to message #595367] |
Tue, 10 September 2013 12:37   |
John Watson
Messages: 8988 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
And here's my latest attempt to boil the bunny:
orclz> ed
Wrote file afiedt.buf
1 With mydata As
2 ( Select 11 thevalue from dual union all
3 Select 156 from dual union all
4 Select 199 from dual union all
5 Select 44 from dual
6 )
7 Select thevalue
8 , to_number(substr(to_char(thevalue),1,length(to_char(thevalue)) - 1)||'0')+10
9* From mydata
orclz> /
THEVALUE TO_NUMBER(SUBSTR(TO_CHAR(THEVALUE),1,LENGTH(TO_CHAR(THEVALUE))-1)||'0')+10
---------- --------------------------------------------------------------------------
11 20
156 160
199 200
44 50
orclz>
|
|
|
|
|
Re: Next multiple of 10 value for the given integer [message #595413 is a reply to message #595395] |
Wed, 11 September 2013 01:55   |
John Watson
Messages: 8988 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
Of all the solutions, I think the ebrian(modified) algorithm is the best in that it handles fractions and both positive and negative values. However, the handling of negatives requires further modification if the results are conform to the generally accepted standard of "round away from zero":
1 With mydata As
2 ( Select 10 val from dual union all
3 Select -21 from dual union all
4 Select -35.2 from dual union all
5 Select 156.1 from dual union all
6 Select 199 from dual union all
7 Select 44 from dual
8 )
9 Select val
10 , decode(sign(val), '-1', -1*ceil(abs(val)/10), ceil(val/10))*10 roundup
11* From mydata
orclz> /
VAL ROUNDUP
---------- ----------
10 10
-21 -30
-35.2 -40
156.1 160
199 200
44 50
6 rows selected.
orclz>
This has to be the best solution. Though as Sai has not responded to any of this, I suppose she has lost interest. Or perhaps she found the references to domestic animals to be little off-putting.
|
|
|
|
|