Solved

Rounding down to the nearest 5

Posted on 2013-05-15
11
450 Views
Last Modified: 2013-05-16
Gurus,                                                    
                                                         
I need some help rounding down to the nearest 5.          
                                                         
Example                                                  
                                                         
before:                                                  
                                                         
r-price = 100.00                                          
s-price = 42.00                                          
                                                         
percent saved % = 58                                      
dollar amount saved = 58.00                              
                                                         
after:                                                    
                                                         
r-price = 100.00                                          
s-price = 42.00                                          
                                                         
percent saved % = 55                                      
dollar amount saved = 55.00                              
                                                         
So if the value is 51 - 54 round to 50 and 56-59 round 55.

How do I accomplish this in my trigger?

create or replace                                                                            
TRIGGER "SALE_CALCULATIONS" BEFORE                                                            
  INSERT OR                                                                                  
  UPDATE ON Prs FOR EACH Row                                                                  
                                                                                             
BEGIN                                                                                        
                                                                                             
:New.Prsvf17c := (:New.Prsprsc - :new.prsvf1c);                            
:New.Prsvf11c := ((:New.Prsprsc - :new.prsvf1c)/:new.prsprsc *100)||'%';
                                                                                                       
END;  
0
Comment
Question by:xbox360dp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 3

Expert Comment

by:pjevin
ID: 39169115
Round(:New.Prsvf11c*2/10)/2*10
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 39169172
ceil((:New.Prsprsc-4)/5)*5
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39169174
>>Round(:New.Prsvf11c*2/10)/2*10

I found that with Google as well.
However,  59 gives you 60 not 55.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 3

Expert Comment

by:pjevin
ID: 39169231
Ah, sorry I missed the rounding down part, thought it was just the nearest 5.. just subtract 2 first.

Round((:New.Prsvf11c-2)*2/10)/2*10
0
 
LVL 3

Expert Comment

by:pjevin
ID: 39169252
2.5 if you have a possibility of decimals, but ceil or floor or whatever you want works too, just not compatible with all databases.
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 39169283
>>> just not compatible with all databases.

well, this was asked in the Oracle topic area, but even if we extend to other platforms, out of curiosity, which ones were you thinking of that don't have a ceiling function or equivalent?
0
 
LVL 3

Expert Comment

by:pjevin
ID: 39169333
It had a "SQL Query Syntax" tag as well... Oracle didn't in early versions, and most other DBs until recently (Informix did not until 11 which is what I was thinking of specifically, and surprisingly even MS Access).  Back in the day, people used to have to do math!
0
 

Author Comment

by:xbox360dp
ID: 39169556
Sdstuber,

Thanks for the feedback ... but how do I incorporate your examples in the trigger I have in my question?
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 39169701
what column do you need rounded?

put something like this in your trigger where xxxxx is the column you need rounded


:new.xxxxxx := ceil((:New.xxxxx-4)/5)*5 ;
0
 

Author Comment

by:xbox360dp
ID: 39169748
So ..

:New.Prsvf19c := (ceil(((:new.prsprsc - :new.prsvf1c-4) / :new.prsprsc * 100)  / 5) * 5) || '%'; ??
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 39169852
if you say so

this is the first time you've posted anything about the Prsvf19c  column.


what value will have 58 that you need rounded down to 55?

that's the one you need to put in the xxxxxx  here.


 ceil((xxxxxx-4)/5)*5 ;


then assign that to whatever you column it belongs in,  with '%' appended if you want.

basically, the math is already defined for you.
but only only can decide which columns that math applies to
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Merge join vs exist 3 37
Sorting a SQL script 5 42
SQL query joining 6 tables in asp.net 4 34
SQL Query returning inflated numbers 1 15
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question