Home » Developer & Programmer » Forms » Calculation of numbers (Forms6)
Calculation of numbers [message #493117] Sat, 05 February 2011 02:56 Go to next message
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 #493120 is a reply to message #493117] Sat, 05 February 2011 03:16 Go to previous messageGo to next message
Michel Cadot
Messages: 68684
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Explain your addition rules.

Regards
Michel
Re: Calculation of numbers [message #493140 is a reply to message #493117] Sat, 05 February 2011 07:53 Go to previous messageGo to next message
isohail
Messages: 7
Registered: February 2011
Location: Pakistan
Junior Member
Thanks for reply.

For example in one field of a table i have stored the number of bags i.e
Bags consumed
5.20 i.e(5 bags and 20 cones)
3.24 i.e(3 bags and 24 cones)
2.54 i.e(2 bags and 24 cones)
7.36 i.e(7 bags and 36 cones)

I want the sum of these numbers.
select sum(bags_consumed) from some table

if I sum up these numbers in regular way it will give me the result
18.34
But I want this result 23.14
Because I have already explained that 1 bag= 24 cones
Re: Calculation of numbers [message #493150 is a reply to message #493140] Sat, 05 February 2011 09:33 Go to previous messageGo to next message
Michel Cadot
Messages: 68684
Registered: March 2007
Location: Nanterre, France, http://...
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

Re: Calculation of numbers [message #493176 is a reply to message #493117] Sun, 06 February 2011 07:12 Go to previous messageGo to next message
isohail
Messages: 7
Registered: February 2011
Location: Pakistan
Junior Member
thank you for your reply
Sorry Michel you are right it is 22.14
I have understood
but if you explain how it can be done if we add two text boxes values on a form and result will be 22.14
Re: Calculation of numbers [message #493180 is a reply to message #493176] Sun, 06 February 2011 08:11 Go to previous messageGo to next message
Michel Cadot
Messages: 68684
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
I don't know forms, I show you how to do it mathematically and how to do it in SQL.

Regads
Michel
Re: Calculation of numbers [message #493194 is a reply to message #493180] Sun, 06 February 2011 11:14 Go to previous messageGo to next message
cookiemonster
Messages: 13938
Registered: September 2008
Location: Rainy Manchester
Senior Member
Write a procedure that does the calculation. Call it from the when-validate-item trigger on each of the two items you want to add.
Re: Calculation of numbers [message #493235 is a reply to message #493117] Mon, 07 February 2011 00:24 Go to previous message
isohail
Messages: 7
Registered: February 2011
Location: Pakistan
Junior Member
Ok Thanks Everyone
Previous Topic: VB Activex DLL - How to Integrate with Oracle Forms
Next Topic: Tree View Query
Goto Forum:
  


Current Time: Tue Sep 17 16:22:15 CDT 2024