Calculation of numbers [message #493117] |
Sat, 05 February 2011 02:56 |
|
isohail
Messages: 7 Registered: February 2011 Location: Pakistan
|
Junior Member |
|
|
Hello Experts
I am developing a form where I need to add Numbers.
In fact we have a bag of Cones that contain 24 cones.
In normal calculation when I add numbers for example
5.24 Plus 5.24 it will give the result 10.48
I Need the appropriate method to calculate if I add these two numbers it should give the result
5.24 Plus 5.24 the result should be 12
|
|
|
|
|
Re: Calculation of numbers [message #493150 is a reply to message #493140] |
Sat, 05 February 2011 09:33 |
|
Michel Cadot
Messages: 68732 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
I think the result is 22.14 because 20+24+54+36 = 134 = 5*24+14 = 5 bags + 14 cones and 5+3+2+7 = 17 bags, so total is 22.14.
I think what you posted is not logical, if integer part represents bag and so 24 cones and decimal part represents number of cones (that is part of a bag) then:
1) How does it come that some decimal numbers are greater than 24? Does 0.24 should be written 1?
2) You cannot directly sum in base 10 and then convert the decimal part into bags
There are several ways to write it, take the one you understand from what I said:
SQL> with
2 data as (
3 select 5.20 val from dual
4 union all
5 select 3.24 val from dual
6 union all
7 select 2.54 val from dual
8 union all
9 select 7.36 val from dual
10 )
11 select sum(trunc(val)) + trunc(sum(100*mod(val,1))/24) + mod(sum(100*mod(val,1)),24)/100 res1,
12 trunc(sum(24*trunc(val)+100*mod(val,1))/24) + mod(sum(24*trunc(val)+100*mod(val,1)),24)/100 res2
13 from data
14 /
RES1 RES2
---------- ----------
22.14 22.14
Regards
Michel
[Updated on: Sat, 05 February 2011 09:34] Report message to a moderator
|
|
|
|
|
|
|