Round away from zero

BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE     11.2.0.1.0     Production
TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - ProductionI have been tasked to write a function to round away from zero
I would like it to be the same as oracle round
  round(n , integer )
  http://www.di.unipi.it/~ghelli/didattica/bdldoc/B19306_01/server.102/b14200/functions135.htmwith the following exceptions if no value is given for the second parameter (integer) a default of 2 is used
because this is typically for pennies
the other exception is that it rounds away from 0 as in round_away_from_zero(2.351) = 2.36 and round_away_from_zero(2.32,1) = 2.4
I am close but do not quite have it.
create or replace function round_away_from_zero   (v_n number, v_integer pls_integer default 2) return number as
begin
     case mod(v_n,.1*(v_integer - 1)) when 0 then
       return trunc(v_n,v_integer);
      else
      return trunc(v_n,v_integer)+ power(.1,v_integer);
      end case;
end; here are my current incorrect results
with t as ( select 1.231 nbr from dual union
                select 1.101   from dual union
                select 1.600 from dual union
                select 1.423 from dual union
                select .30 from dual union
                select .9 from dual union
                select 1.0001 from dual union
                select 10 from dual
select nbr,  round_away_from_zero(nbr,0),  round_away_from_zero(nbr,1), round_away_from_zero(nbr,2)
from t;
NBR     ROUND_AWAY_FROM_ZERO(NBR,0)     ROUND_AWAY_FROM_ZERO(NBR,1)     ROUND_AWAY_FROM_ZERO(NBR,2)
0.3     0     0.4     0.3
0.9     0     1     0.9
1.0001     2     1.1     1.01
1.101     2     1.2     1.11
1.231     2     1.3     1.24
1.423     2     1.5     1.43
1.6     1     1.7     1.6
10     10     10.1     10here are my expected resulst
NBR     ROUND_AWAY_FROM_ZERO(NBR,0)     ROUND_AWAY_FROM_ZERO(NBR,1)     ROUND_AWAY_FROM_ZERO(NBR,2)
0.3     1     0.3     0.3
0.9     1     0.9     0.9
1.0001     2     1.1     1.01
1.101     2     1.2     1.11
1.231     2     1.3     1.24
1.423     2     1.5     1.43
1.6     2     1.7     1.6
10     10     10     10

Hi,
Carlovski's solution is great for numbers greater than or equal to 0.
If you want negative numbers to round away from 0, you can do something like this:
SELECT  nbr
,       SIGN (nbr) * CEIL ( ABS (nbr)
                           * POWER (10, :v_integer)
             / POWER (10, :v_integer)     AS round_away
FROM    t;Output, with some negative numbers, and :v_integer = 1:
`      NBR ROUND_AWAY
       -10        -10
      -1.6       -1.6
    -1.423       -1.5
    -1.231       -1.3
    -1.101       -1.2
   -1.0001       -1.1
       -.9        -.9
       -.3        -.3

Similar Messages

  • I want to access my library on my macbook pro and copy work done away from home from my imac how do I do this?

    I want to access my library on my macbook pro and copy work done away from home to Aperture on my imac how do I do this?

    Are you working on images on both machines?
    If you want to round-trip images, you can export a project as a library from your iMac, copy that to your MacBook Pro, and then edit the images there.  When you're done, copy that library back to the iMac and import it to your iMac.  The iMac should recognize the changes you've made and update its images.
    Read the Aperture help file, which will guide you to the Aperture manual.  It can walk you through this.  You have to be careful to do it correctly, but I've done this a few times and it works quite well.

  • TS1398 How do I connect to the internet with my iphone when away from home

    I have an iphone 3GS which was fine , was able to connect to the internet away from home when at uni, at appointments. Since software update to IOS 6.0, can now only connect to internet wirelessly when at home-as soon as leave the house it disconnects. Is this just because of the software update? Have tried adjusting settings but got nowhere. Thank you

    When your wifi is off.  Do you see your carrier name at the top left with either 3G/4G.  If not you can try a reset, hold down the home/power button until you see the apple logo and then release, then wait for the phone to boot back up.
    or settings - cellular - cellular data - ON
    if those two suggestion doesn't help then you will need to contact your phone carrier to resolve the issue.

  • I have a mac book air 11". When I boot up connected to the huge Thunderbolt  screen it detects the detects the fact and gives me great quality. now I am travelling away from the scree it boots up, nice picture, then switches to rubbish resolution.

    I have a Mac Book air 11". Normally at home I connect this to a large Thuderbolt Screen. When booting up it some times gets confused and offers me a low resolution result, but some plugging and unplugging of the screen fixes this. I assume it sometimes "sees" the big screen and sets the resolition accordingly. Sometimes does not. But now... I am away from big screen and cannot get the Macbook air on its one to deliver anything other than really poor resolution. I ahve done displays and chosen all three - but no better. And I have said Choose the Best ONe... again not luck. Any ideas. I read in back posts this was a problem a few years ago.

    Welcome to Apple Discussions
    I believe you have a failing GPU (aka Video Card). Run AHT and see what it tells you. Do not be afraid to run it up to three times in succession if at first it does not detect an error (sometimes errors that are caused by overheating will not show up until the computer is stressed enough - repeating AHT will do that).
    As an aside - the MBA was not designed to take the place of a desktop. If you are powering your MBA by leaving it permanently attached to the thunderbolt port on the monitor you are shortening your battery life.

  • Using Outlook 2007 I want to receive emails on my iPhone 4 only when Outlook is NOT open on my computer, as when away from home or want to quickly check email when computer is not turned on. Either ALL emails come to my iPhone or none at all.

    Using Outlook 2007 I want to receive emails on my iPhone 4 only when Outlook is NOT open on my computer, as when away from home or want to quickly check email when computer is not turned on. Either ALL emails come to my iPhone or none at all. Is the setting I need to change in Outlook or on the iPhone or is it somewhere else?  I used to have this setting but transferring Outlook to a new laptop somehow turned it off.

    No. You really can't do that. Not easily at any rate. You would have to set them both up to use POP3, but even then there is no way to guarantee that the phone won't poll the server prior to your computer doing so, pulling down the message from the server.

  • HT4979 why can I not send email when away from my home wifi? Am able to receive messages OK, and outgoing mailserver is correct?

    Why am I unable to send email when away from my home wifi ? I am able to receive mail OK, and have double- checked the outgoing server which is correct. This problem is consistent with my Macbook Pro, iPhone, and iPad2.
    Attempts to send messages results in them sitting in the Outbox and never- ending 'sending message' displayed.
    I am able to send using my   me.com  server.
    Home service provider is Cogeco.
    Any help would be appreciated.

    iOS: Unable to send or receive email
    http://support.apple.com/kb/TS3899
    Can’t Send Emails on iPad – Troubleshooting Steps
    http://ipadhelp.com/ipad-help/ipad-cant-send-emails-troubleshooting-steps/
    iPad Mail
    http://www.apple.com/support/ipad/mail/
    Try a Reset - iPad How-Tos  http://ipod.about.com/lr/ipad_how-tos/903396/1/
    Or this - Delete the account in Mail and then set it up again.
     Cheers, Tom

  • Wifi works at home but not when away from home

    My Wifi works at home but not when away from home, what is wrong?  I thought with a phone plan I didn't need to have a wifi connection.

    You either need WiFi or Cellular (or both). If you have neither, you can't connect to the internet.
    Most people use WiFi at home and Cellular while away from home, or connect to public WiFi networks where there are some.

  • Firefox crashes as soon as I move away from my homepage.

    Firefox crashes as soon as I move away from my homepage. This start right after I tried to load the 3.6.8 update
    == User Agent ==
    Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; GTB6.5; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; InfoPath.2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; AskTB5.8)

    Hi ..
    Troubleshooting steps here >  iOS: Troubleshooting Wi-Fi networks and connections

  • Firefox crashes every time I try to navigate away from a page to a different site.

    It seems to only happen when I have more than one tab open, but every time I try to navigate away from the originally opened page, it crashes. This has just started happening today (3/19/14) and I have tried to resetting Firefox but it did not remedy the problem.

    hello, could you provide your latest few submitted crash reports? please enter '''about:crashes''' into the location bar, copy the latest few report ids from there & paste them here into a forum reply. this will give us a better understanding what may be triggering those crashes.

  • I am often away from my computer for weeks at a time, digging at archaeology sites, before I return to clean, sort, and catalog my finds. And every time I launch my browser of choice, I have to sit through yet another Firefox update.

    Sometime's it's a major update, like Firefox 3.6 for instance, but more often than not—too often—it's some stupid little tertiary update that requires Firefox to download, quit, root around on the hard drive, and restart with a whole damn brand-new binary. Why?!
    Just once I'd like to sit down, boot up, and get to work instead of wading through this slow, irritating process that the Mozilla developers subject me to.
    I've become envious of my friends who run Safari, Apple's home-grown browser, which is updated less frequently. If they want more frequent updates, they download and install WebKit, but can otherwise continue on day after day without interruption in Safari.
    I like this model, as it lets busy people like me get more work done, so I am thinking of purchasing a Mac. Really, anything to get me away from the time-wasting wreck of a browser that Firefox has become is a good idea.
    The Firefox model crashes and burns its users. Literally, too, when you think about all of its other addling bugs and design flaws that crash the browser and burn countless CPU cycles.
    So until I can see the web in a whole new way with Safari on a new Mac, it'll be another day, another Firefox update.
    Thanks a lot for nothing, Mozilla.
    == This happened ==
    Not sure how often
    == I installed Firefox. ==
    == User Agent ==
    Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/531.22.7 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7

    Hello Matt, fellow archaeologist :)
    Security updates are essential on any and all software, specially your browser. Mozilla is working to streamline the updating process as much as possible, but you shouldn't neglect your own security for a few seconds of "wasted" time.
    I hope you do the best for yourself.

  • DW CS6 - Spry collapsible panels - How to have panel close when you click away from it?

    I know typically onmouseout is used to close other items, but I could not figure it out with the spry collapsible panel. I have the panel opening onclick and closing onclick, but I would really like for it to close when you click anything else on the page outside of the panel.
    Thank you!

    Sorry, I did not mean other collapsing panels close when you click away from it. I simply meant in general for the closing after clicking away function, you can use onmouseout. I was working on something with collapsing panels and I wanted it to show the information when you clicked on it, but when you click on another panel, they both remain open. I really want both to close. I believe accordion does this, but not quite what I am looking for either.
    Here is a better example of what I would prefer: Houston Public Library
    If you visit their page and click "Find it" a box pops down with information and then when you click anywhere else on the screen, it closes that box. When you click "Research," it closes the "Find It" box and opens the "Research" box. There is likely a much better way to do this, but I am pretty new to this.
    Any assistance is very much appreciated.
    Thank you!

  • I have a new iphone5 and would like to have my own itunes list away from the familys itune list

    i have a new iphone5 and would like to have my own itunes list away from the familys itune list?
    i have now got my own apple id account but where do i go from here?
    thanks danny.

    The user data is store in the profile folder. You can copy the data manually by copying the contents of the profile folder, for details see [http://kb.mozillazine.org/Profile_backup Profile backup - MozillaZine Knowledge Base] or [[Backing up your information]].
    There are some add-ons and utilities that can make this process easier. The first one is the [https://addons.mozilla.org/en-US/firefox/addon/2109/ FEBE] add-on which can be used to copy a profile. Another option is the free [http://mozbackup.jasnapaka.com/ MozBackup] utility.

  • Can I use iTunes Match while I'm away from Home, and my family still use Home Sharing via Apple TV?

    I would like to be able to use my iTunes Match account as I am frequently away from home.
    However, my family would also like to be able to use Home Sharing to listen to music, watch movies stored on the family iMac, using the Apple TV.
    At the moment, iTunes Match & Apple Store uses a different Apple ID to Home Sharing.  I don't want the kids to be able to download movies etc on the Apple TV.
    Is there a way that I can achieve both at the same time?

    Yes, iTunes Match alleviates this situation.  As long as iTunes on both of your computers is using the same Apple ID, you can add songs to either one, and once they have uploaded to iCloud, they will be available on any of your iDevices AND in iTunes on the other computer.

  • TS1741 Can u use home sharing whilst u are away from home

    Can u use home sharing whilst u are away from home

    Oh, so is THAT where the name "HOME SHARING" comes from? 

  • HT201250 i am using for first time the time machine and an external hard drive because I want to erase my macbook and start from zero files. do i keep my files in the portable hard disk when I connect it again with the macbook or the time machine will era

    i am using for first time the time machine and an external hard drive because I want to erase my macbook and start from zero files. Am i keeping my files in the portable hard disk when I will connect it again with the macbook or the time machine will erase all?
    I would like to know if after I erase all my data, empy hard drive inside the macbook, the time machine will erase all my files that I have saved in my "WD "My passport" external hard drive

    Welcome to Apple Support Communities
    Time Machine has to erase the external disk in order to make backups. Before setting Time Machine up, copy the files of your external disk to the hard disk of the Mac in order not to lose them, and then, set up Time Machine. The first backup will start automatically.
    If you want more information about Time Machine, read the Pondini's site > http://pondini.org

Maybe you are looking for

  • Error Code 10 with GPIB PCI Card

    PC used: Dell optiplex GX110, lastest Bios release, Windows 2000 SP4, GPIB Drivers version 2.2, Local Admin session. After having install the driver (without the GPIB)and plug the card, this one is automaticaly recognised by the Os. But, after the re

  • PS web photo gallery?

    I created a web gallery in PS2. After I post to my web site, the window is 800x600 and the vertical photos need to be scrolled. There is lots of gray around the photos. How do I expand the web gallery to fill screens better. Maybe 1024x768.

  • HT3988 how to connect external keyboard to the garage band if its possible

    how to connect external keyboard to the garage band if its possible,   is any body tried ? I have roland e66 keyboard and im trying to    connect with grage band but i dont know thats is possible??

  • Sql loader - BLOB

    I have used OMWB "generate Sql Loader script " option. ANd received the sql loader error. The previous attempt to use OMWB online loading has generated garbage data. The picture was not matching with the person id. Table in Sql Server................

  • Multiple xml signatures

    I have an xml document, in which I want to sign a certain portion of it. and there will be multiple people signing this ? What is the best approach. <a> <b> <c> </c> </b> </a> For example, I want to sign document from node <b> and many users will sig