Catching errors such as divide by zero and typing non-numeric characters

Fellows: How do I extend following script to catch errors such as divide by zero and typing non-numeric characters.      Thanks
This program takes two integers (whole numbers), then displays the sum, average, division,
Modula of those numbers and finally the first number raised to the power of the second number.
import java.io.*;
public class HWOne
     public static void main(String[] args) throws IOException  // error handling
          // variable declaration
          String firstdigit, seconddigit;
          int first, second, sum, total, modus, power;
          float division;
          double average;
          BufferedReader myIn = new BufferedReader(new InputStreamReader(System.in));
          //Invoke user response
          System.out.print("Please enter first digit ");
               firstdigit = myIn.readLine();
               first = Integer.parseInt(firstdigit);
          System.out.print("Please enter second digit ");
               seconddigit = myIn.readLine();
               second = Integer.parseInt(seconddigit);
          //computations
          sum = first + second;
          average = (double)sum / (double)2;
          division = (float)first / (float)second;
          modus = first % second;
          power = (int)Math.pow(first, second);
          //Screen message
          System.out.println("Sum: " + sum);
          System.out.println("Average: " + average);
          System.out.println("Division: " + division);
          System.out.println("Modula: " + modus);
          System.out.println("Power: " + power);

Have you learnt about try/catch statements yet?
The parseInt method throws a NumberFormatException. So you place the call to that method inside a try statement and catch the exception.
For divide by zero, you can use an if statement. If the divisor != 0 perform division.

Similar Messages

  • FM WHICH adds leading zeroes to a non numeric input

    hi i need the<b> fm name</b> which will add leading zeroes to anu non numeric input
    say
    input is <b>ABC</b>
    SO MY OUTPUT SHOULD BE
    <b>000000000000ABC</b>
    URGENT
    NEED A FUNCTIOJN MODULE NAME

    i think no fn module is there for non numeric values to add zero do like this..
    data : text(20) value 'ABC',
           len type i.
    compute len = strlen( text ).
    len = 20 - len.
    do len times.
    concatenate '0' text into text.
    enddo.
    write : / text.
    regards
    shiba dutta

  • Does anyone have advice on how to resolve iPhoto libary not loaded error?  Tried reinstalling Snow Leopard and iLife '11 numerous times and it didn't help

    Full error message:
    Process:         iPhoto [186]
    Path:            /Applications/iPhoto.app/Contents/MacOS/iPhoto
    Identifier:      com.apple.iPhoto
    Version:         ??? (???)
    Build Info:      iPhotoProject-6070000~1
    Code Type:       X86 (Native)
    Parent Process:  launchd [109]
    Date/Time:       2011-05-22 17:58:45.673 -0400
    OS Version:      Mac OS X 10.6.7 (10J869)
    Report Version:  6
    Interval Since Last Report:          92376 sec
    Crashes Since Last Report:           7
    Per-App Crashes Since Last Report:   7
    Anonymous UUID:                      35BCDA2A-2D88-405A-9BCA-D16A84AE6E15
    Exception Type:  EXC_BREAKPOINT (SIGTRAP)
    Exception Codes: 0x0000000000000002, 0x0000000000000000
    Crashed Thread:  0
    Dyld Error Message:
      Library not loaded: /Library/Frameworks/iLifeSlideshow.framework/Versions/A/Frameworks/iLifeSlidesh owProducer.framework/Versions/A/iLifeSlideshowProducer
      Referenced from: /Library/Frameworks/iLifeSlideshow.framework/Versions/A/iLifeSlideshow
      Reason: image not found
    Binary Images:
    0x8fe00000 - 0x8fe4162b  dyld 132.1 (???) <1C06ECD9-A2D7-BB10-AF50-0F2B598A7DEC> /usr/lib/dyld
    Model: MacBookAir1,1, BootROM MBA11.00BB.B03, 2 processors, Intel Core 2 Duo, 1.6 GHz, 2 GB, SMC 1.23f20
    Graphics: Intel GMA X3100, GMA X3100, Built-In, 144 MB
    Memory Module: global_name
    AirPort: spairport_wireless_card_type_airport_extreme (0x14E4, 0x8B), Broadcom BCM43xx 1.0 (5.10.131.36.9)
    Bluetooth: Version 2.4.0f1, 2 service, 19 devices, 1 incoming serial ports
    Network Service: AirPort, AirPort, en0
    Parallel ATA Device: SAMSUNG HS082HB, 74.53 GB
    USB Device: Built-in iSight, 0x05ac  (Apple Inc.), 0x8505, 0xfd400000
    USB Device: USB 2.0 Hub, 0x1a40  (TERMINUS TECHNOLOGY INC.), 0x0101, 0xfd100000
    USB Device: My Passport 070A, 0x1058  (Western Digital Technologies, Inc.), 0x070a, 0xfd140000
    USB Device: Apple Internal Keyboard / Trackpad, 0x05ac  (Apple Inc.), 0x0223, 0x5d200000
    USB Device: IR Receiver, 0x05ac  (Apple Inc.), 0x8242, 0x5d100000
    USB Device: BRCM2046 Hub, 0x0a5c  (Broadcom Corp.), 0x4500, 0x1d200000
    USB Device: Bluetooth USB Host Controller, 0x05ac  (Apple Inc.), 0x8210, 0x1d210000

    Did you delete the receipts with iPhoto in the file name before reinstalling iPhoto?
    You have to delete the current application and all files with "iPhoto" in the file name with either a .PKG or .BOM extension that reside in the HD/Library/Receipts folder and from the /var/db/receipts/  folder,
    Click to view full size
    Then install iPhoto from the disks it came on originally and apply the latest, applicable updates.
    OT

  • Adding leading zeros to a non-numeric field

    Hello
    I have an application which currently does not validate a field and the user can enter any string on this specific field. The customer wants me to write a view to bring information from a child table which uses the free format field as the key to join.
    Example, the field A is free format, but, we would expect something like "0000001-AB', however the users are inputing '1' or '001-AB'. The client wants to see these cases to be displayed (and joined) as '0000001-AB'. The format is 7 digits + '-' + two digit code.
    I would like to know, how can I display this on a view, since most of my cases are '1' or '001-AB'. But there are others with crazy things like '1+2+3+4' and these cases are giving me an error of "invalid number" since I am using the TO_NUMBER function so far.
    Thanks!
    Eduardo Ferrari

    WITH t AS (SELECT '1' txt FROM DUAL
               UNION
               SELECT '001-AB' FROM DUAL
               UNION
               SELECT '1+2+3+4' FROM DUAL)
    SELECT CASE
              WHEN LENGTH ( (REGEXP_REPLACE (txt, '[-AB]') || '-AB')) < 10
              THEN
                 LPAD ( (REGEXP_REPLACE (txt, '[-AB]') || '-AB'), 10, '0')
              ELSE
                 REGEXP_REPLACE (txt, '[-AB]') || '-AB'      
             end  txt
    from t
    TXT
    0000001-AB
    0000001-AB
    1+2+3+4-ABunion
    Edited by: pollywog on Nov 10, 2010 3:41 PM
    Edited by: pollywog on Nov 10, 2010 3:53 PM

  • At startup-system error and divide by zero

    I've been having a lot of problems starting up my beige G3 mini tower, it has 233mhz, 384ram, mac os9.1. I've zapped the pram and held the shift key down to boot with extensions off, didnt work. I've changed the battery twice in case the first replacement was bad, it started up and ran long enough for me to trash all the preferences, I tried to change the extensions, but when restarting it was back to not completely starting up. I've tried pressing the button near the pci slots with the battery out, 30 seconds, waited 30 minutes and held down the button for another 30 seconds, replaced the battery, checked the sound card for looseness then at startup it worked till I changed the time and date. I tried the battery and button again this time waiting over night between pressing the button for 30 seconds, after startup I was able to run disc first aid and it said everything was ok, then crashed again when I tried to change the date and time. I've even tried booting up from command/option/o/f, I'm not sure what firmware is but it would try to start up that way,but was very slow with a os cd in the cd drive. I tried to erase the hard drive but I couldnt get it to start up from a cd, iv'e tried os9, the original cd that came with the computer and a system recovery cd.
    Most times when trying to start it up it chimes, then the happy mac with a grey screen, then the mac os screen, then the bomb with "system error" and under that "bus error" under that it says to restart with extensions off. sometimes the button for restart will even work with the cursor. Once, after trying to start up after all the battery removal, pressing button near pci slots , pressing com/opt/o/f, extensions off, the screen getting to the mac os then the bomb dialogue, it said system error and instead of saying "bus error" it said "divide by zero". Thats the first and only time I've seen that one. Also, the grey screen (with the happy mac disc icon) now has horizontal lines with texture? that I havent noticed before.
    got any ideas what I should do next? I probably wouldnt bother with my G3 anymore because I just bought a new Imac, but I have a vinyl cutter hooked to it, it has the old round serial port cables and I would have to buy new software, cables and dongle to use it with my new Imac, I also have illustrator, photoshop, scanner, and drawing tablet on my G3 that I cant use on my new Imac (intel) leopard.
    Is my hard drive or motherboard dying? is there a way to find out if and what hardware is messed up? and if so, is there still still parts out there for this G3?

    Hi, R1camper -
    I ran disc first aid from the cd and and it said it couldnt fix-overlapped extent allocation,4,479.
    That is a type of disk directory damage, one which Disk First Aid can not repair.
    Alsoft's DiskWarrior can usually repair that kind of damage, with no loss of files. If you choose to go this route, suggest you call (or email) Alsoft's sales department, and request an older version of DiskWarrior - the current versions won't run on your Beige G3/MT.
    However, if you can manage to live with the loss of files, you can probably replace the hard drive for less cost.
    Your Beige G3/MT came with either an ATA (now often referred to as PATA and/or IDE) drive or a SCSI drive - it could have been ordered with either when the machine was new.
    With luck it will be an ATA drive, since those are the least expensive and the easiest to install. Such drives are not Mac-specific - any ATA drive designed for internal use and of appropriate size will work. The only item of concern is to set the drive's jumpers properly. The drive should be jumpered as Master (it may come preset as Master or as Cable Select - Cable Select will not work on your model), unless it is a Western Digital in which case it should be set to Single if that is an available choice.
    There is probably little to gain by getting a 7200RPM drive, especially if there is extra cost for one vs. a 5400RPM drive - the relatively slow internal bus speed on your machine will not be able to take significant advantage of a faster drive.
    Re the RAM, if you have the time you might try replacing any you took out. Over time the contact the module makes in its slot can get iffy - removing and replacing the module usually fixes that problem, by wiping the contacts clean.

  • Attempted to divide by zero. Error while executing the script

    Hi All,
    I using a script I found long back and I'm trying to use to get disk space info from different servers with separate credentials.
    I'm getting the below error and it has eaten my head but I'm not able to figure out where the problem lies in the code.
    Attempted to divide by zero.
    At D:\psscripts\ww.ps1:92 char:26
    + $freePercent = ($frspace/ <<<< $totSpace)*100
    + CategoryInfo : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException
    I'm open to use any other way to find me Disk Space with different credentials..here security isn't a question.
    This script uses computers.csv to reference the computer name and the referenced credentials in the script.
    Thanks in advance
    $freeSpaceFileName = "c:\script\FreeSpace.htm"
    $warning = 50
    $critical = 30
    New-Item -ItemType file $freeSpaceFileName -Force
    $ComputerList = Import-Csv -Path d:\Computers.csv;
    $CredentialList = @{
    Cred1 = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'laptop-pc\administrator', (ConvertTo-SecureString -String 'tamboli' -AsPlainText -Force);
    Cred2 = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'contoso\administrator', (ConvertTo-SecureString -String 'Atlantic12' -AsPlainText -Force);
    Function writeHtmlHeader
    param($fileName)
    $date = ( get-date ).ToString('dd/MM/yyyy HH:mm:ss')
    Add-Content $fileName "<html>"
    Add-Content $fileName "<head>"
    Add-Content $fileName "<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>"
    Add-Content $fileName '<meta http-equiv="refresh" CONTENT="5">'
    Add-Content $fileName '<title>All Servers DiskSpace Report&copy;</title>'
    add-content $fileName '<STYLE TYPE="text/css">'
    add-content $fileName "<!--"
    add-content $fileName "td {"
    add-content $fileName "font-family: Tahoma;"
    add-content $fileName "font-size: 20px;"
    add-content $fileName "border-top: 1px solid #999999;"
    add-content $fileName "border-right: 1px solid #999999;"
    add-content $fileName "border-bottom: 1px solid #999999;"
    add-content $fileName "border-left: 1px solid #999999;"
    add-content $fileName "padding-top: 0px;"
    add-content $fileName "padding-right: 0px;"
    add-content $fileName "padding-bottom: 0px;"
    add-content $fileName "padding-left: 0px;"
    add-content $fileName "}"
    add-content $fileName "body {"
    add-content $fileName "margin-left: 5px;"
    add-content $fileName "margin-top: 5px;"
    add-content $fileName "margin-right: 0px;"
    add-content $fileName "margin-bottom: 10px;"
    add-content $fileName ""
    add-content $fileName "table {"
    add-content $fileName "border: thin solid #000000;"
    add-content $fileName "}"
    add-content $fileName "-->"
    add-content $fileName "</style>"
    Add-Content $fileName "</head>"
    Add-Content $fileName "<body>"
    add-content $fileName "<br></br>"
    add-content $fileName "<table width='100%' align=center>"
    add-content $fileName "<tr bgcolor='#CCCCCC'>"
    add-content $fileName "<td colspan='7' height='25' align='center'>"
    add-content $fileName "<font face='tahoma' color='#003399' size='5'><strong>All Servers DiskSpace Report &copy; - $date</strong></font>"
    add-content $fileName "</td>"
    add-content $fileName "</tr>"
    add-content $fileName "</table>"
    add-content $fileName "<br></br>"
    # Function to write the HTML Header to the file
    Function writeTableHeader
    param($fileName)
    Add-Content $fileName "<tr bgcolor=#CCCCCC>"
    Add-Content $fileName "<td width='10%' align='center'>Drive</td>"
    Add-Content $fileName "<td width='50%' align='center'>Drive Label</td>"
    Add-Content $fileName "<td width='10%' align='center'>Total Capacity(GB)</td>"
    Add-Content $fileName "<td width='10%' align='center'>Used Capacity(GB)</td>"
    Add-Content $fileName "<td width='10%' align='center'>Free Space(GB)</td>"
    Add-Content $fileName "<td width='10%' align='center'>Freespace %</td>"
    Add-Content $fileName "</tr>"
    Function writeHtmlFooter
    param($fileName)
    Add-Content $fileName "</body>"
    Add-Content $fileName "</html>"
    Function writeDiskInfo
    param($fileName,$devId,$volName,$frSpace,$totSpace)
    $totSpace=[math]::Round(($totSpace/1073741824),2)
    $frSpace=[Math]::Round(($frSpace/1073741824),2)
    $usedSpace = $totSpace - $frspace
    $usedSpace=[Math]::Round($usedSpace,2)
    $freePercent = ($frspace/$totSpace)*100
    $freePercent = [Math]::Round($freePercent,0)
    if ($freePercent -gt $warning)
    Add-Content $fileName "<tr>"
    Add-Content $fileName "<td>$devid</td>"
    Add-Content $fileName "<td>$volName</td>"
    Add-Content $fileName "<td>$totSpace</td>"
    Add-Content $fileName "<td>$usedSpace</td>"
    Add-Content $fileName "<td>$frSpace</td>"
    Add-Content $fileName "<td>$freePercent</td>"
    Add-Content $fileName "</tr>"
    elseif ($freePercent -le $critical)
    Add-Content $fileName "<tr>"
    Add-Content $fileName "<td>$devid</td>"
    Add-Content $fileName "<td>$volName</td>"
    Add-Content $fileName "<td>$totSpace</td>"
    Add-Content $fileName "<td>$usedSpace</td>"
    Add-Content $fileName "<td>$frSpace</td>"
    Add-Content $fileName "<td bgcolor='#FF0000' align=center>$freePercent</td>"
    #<td bgcolor='#FF0000' align=center>
    Add-Content $fileName "</tr>"
    else
    Add-Content $fileName "<tr>"
    Add-Content $fileName "<td>$devid</td>"
    Add-Content $fileName "<td>$volName</td>"
    Add-Content $fileName "<td>$totSpace</td>"
    Add-Content $fileName "<td>$usedSpace</td>"
    Add-Content $fileName "<td>$frSpace</td>"
    Add-Content $fileName "<td bgcolor='#FBB917' align=center>$freePercent</td>"
    # #FBB917
    Add-Content $fileName "</tr>"
    foreach ($computer in $ComputerList)
    Get-WmiObject -ComputerName $Computer.Name -Class Win32_LogicalDisk -Credential $CredentialList[$Computer.Credential] | Where-Object {$_.drivetype -eq 3}
    Write-Host $item.DeviceID $item.VolumeName $item.FreeSpace $item.Size
    writeDiskInfo $freeSpaceFileName $item.DeviceID $item.VolumeName $item.FreeSpace $item.Size
    writeHtmlHeader $freeSpaceFileName
    foreach($computer.Name in Get-Content Computers.csv)
    Add-Content $freeSpaceFileName "<table width='100%'><tbody>"
    Add-Content $freeSpaceFileName "<tr bgcolor='#CCCCCC'>"
    Add-Content $freeSpaceFileName "<td width='100%' align='center' colSpan=6><font face='tahoma' color='#003399' size='2'><strong> $server</strong></font></td>"
    Add-Content $freeSpaceFileName "</tr>"
    Add-Content $freeSpaceFileName "<br>"
    writeTableHeader $freeSpaceFileName
    Thanks,

    Hi Taher,
    You got the error "Attempted to divide by zero.", because the input variable $totSpace is null, please note the variable $item when you invoked the function writeDiskInfo:
    >>Get-WmiObject -ComputerName $Computer.Name -Class Win32_LogicalDisk -Credential $CredentialList[$Computer.Credential] |  Where-Object {$_.drivetype -eq 3}
    >>Write-Host  $item.DeviceID  $item.VolumeName $item.FreeSpace $item.Size
    >>writeDiskInfo $freeSpaceFileName $item.DeviceID $item.VolumeName $item.FreeSpace $item.Size
    And you haven't defined the variable $item before you used it, so please refer to the script below:
    foreach ($computer in $ComputerList)
    $items = Get-WmiObject -ComputerName $Computer.Name -Class Win32_LogicalDisk -Credential $CredentialList[$Computer.Credential] | Where-Object {$_.drivetype -eq 3}
    foreach($item in $items){
    Write-Host $item.DeviceID $item.VolumeName $item.FreeSpace $item.Size
    writeDiskInfo $freeSpaceFileName $item.DeviceID $item.VolumeName $item.FreeSpace $item.Size}
    If there is anything else regarding this issue, please feel free to post back.
    Best Regards,
    Anna Wang
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact [email protected]

  • Divide by zero error encountered

    Dear All,
    When our customer process PO, they got an error like below:
    Divide by zero error encountered. Tax definition [ovcg]
    They also got Divide by zero error encountered. Outgoing payments  [ovpm]
    They can process their business but we need to know why and how to fix this error for them.
    Any idea? Thanks.
    Regards,
    Yuka

    Hi,
    You need to check the FMS defined on the row level of the document you want to add.
    Remove the FMS and you will not get the error message reported.
    Kind Regards,
    Jitin
    SAP Business One Forum Team

  • IPod Touch Calculator Divide by Zero

    The iPod Touch Calculator does not return an error on a divide by zero operation. It just displays "0" which is not correct. Is this a know bug? I did a search on this forum and found nothing. How does one report a bug to Apple officially?

    Perhaps the new version of the app due out with the v2.0 Upgrade (with the scientific calculator in landscape mode) will be correct in this regard.
    In any case, report to http://www.apple.com/feedback/ipodtouch.html
    Hope this helps...

  • Inserting strings of printable and non printable characters

    I would very much appreciate some help with the following
    To handle an interface with a legacy system I need to create strings containing both printable and non-printabel ascii characters. And with non printable characters I mean in particular those in the range of ASCII 128 to 159.
    It seems it is not possible to insert a string containting both printable and not printable characters from the afore mentioned range into a VARCHAR2 table column as the following demonstrates:
    insert into test values(chr(156)); -- this inserts the 'œ' symbol.
    SQL> select test, ascii(test), length(test), substr(test,1,1), ascii(substr(test,1,1))from test;
    TEST       ASCII(TEST) LENGTH(TEST) SUBSTR(TEST,1,1) ASCII(SUBSTR(TEST,1,1))
    ┐                  156            1That the the character mapped is shown as '┐' and not 'œ' is not really issue for my application, what is important is that the ASCII value is shown as 156, which is the ASCII code of the character I inserted.
    What is however strange (actually probably not strange but has to do with the lack of understanding of the issue at hand) is that substr returns an empty string...
    Now I try to insert a concatenated string, first the "non printable" character then a printable character
    insert into test values(chr(156)||chr(65));
    SQL> select test, ascii(test), length(test), substr(test,1,1), ascii(substr(test,1,1))from test;
    TEST       ASCII(TEST) LENGTH(TEST) SUBSTR(TEST,1,1) ASCII(SUBSTR(TEST,1,1))
    A                   65            1 A                                     65For some reason the not printable character (chr(156)) is now not inserted or at least does not appear when I selected the data from the table, this effect seems to apply to all characters in the range of ASCII 128 to 159 (tried some but not all) However for instance CHR(13) can be inserted as part of a string as shown above .
    For our application I really don't care much what character is shown or not show, what is important is that I can retrieve the ASCII value and that this value matches the one I inserted which for some reason does not seem to work.
    This seems to be, at least to some extent a character set issue. I have also tested this on a database with character sets set as follows
    NLS_CHARACTERSET
    WE8MSWIN1252
    NLS_NCHAR_CHARACTERSET
    AL16UTF16
    With WE8MSWIN1252 the described issue does NOT occur, however unfortunately I must use NLS_CHARACTERSET AL32UTF8 which produces the results as described above!
    As said any insights would be much appreciated as I am slowly but surely starting to despair.
    For completions sake, character sets are set as follows (changing it is NOT an option):
    NLS_CHARACTERSET
    AL32UTF8
    NLS_NCHAR_CHARACTERSET
    AL16UTF16
    The test table is created as follows
    CREATE TABLE TEST
    TEST VARCHAR2(1000 BYTE)
    Database Version 11.2.0.3.0
    Edited by: helios.taraba on Dec 2, 2012 10:18 AM --Added database version
    Edited by: helios.taraba on Dec 2, 2012 10:24 AM Added description of test results using NLS_CHARACTERSET WE8MSWIN1252

    Hello Orafad,
    Thanks for your reply, at least I understand the effects I'm seeing i.e.
    +"For multibyte character sets, n must resolve to one entire code point. Invalid code points are not validated, and the result of specifying invalid code points is indeterminate."+
    http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions026.htm
    You are absolutely right I could use chr(50579) to get the ligature symbol. However as what we are trying to achieve is to implement a legacy interface to a 20+ years old subsystem we are actually not so much interested in the symbol itself but rather in the ascii value of that symbol (156 as you so rightly point out in the win-1252 characterset), this particular field represents the lenght of the message being sent to the subsystem and can vary from decimal 68 to 164 and is also considered in a checksum calculation which is part of the message.
    As changing the nls_characterset of the database is not an option I guess I only have one reasonable avenue to resolve this namely to push the functionality to added the "encoded" length of the message (and the calculation of the checksum) to the java driver which is responsible for sending the message (tcp/ip) to the subsystem. Here we should not have any issues adding a byte with the value 156 (or any other for that matter) to the datastream.
    Thankfully all other fields have characters with ascii values below 128 and above 31.
    I'm going to leave my question as un-answered for a bit longer in the hopes of someone coming up with a golden bullet, although not getting my hopes up.
    Thanks, Helios

  • Arithmetic Overflow/Underflow and Divide by Zero Errors

    We're having problems similar to those posted below (see links), especially "Help: Divide by Zero Errors" to which no one has addressed. <br /><br />Here's our situation: On our form, we have two columns that sum the rows above them, called<br /><br />"covertotal" and "multtotal"<br /><br />...for which we need a final calculation: multtotal/covertotal<br /><br />Under calcutions in FormCalc, we have generated the following formula for the box called "prevtotal" under the calculate command: <br /><br />(multtotal / covertotal)<br /><br />However, since this calculation runs when the document is opened, we get a divide by zero error. Do we need to create an initialize or calculate formula to correct for this zero? If so, what is the proper coding.<br /><br />Please spell this out, we're that stupid... <sigh><br /><br />Thanks!<br /><br />Matthew<br /><br />Previous posts with similar problems are linked below:<br /><br />Help: Divide by Zero Errors<br /><a href="/cgi-bin/webx?14@@.3bbd2077">Harry Kontos, "Help: Divide by Zero Errors" #, 6 Nov 2005 10:01 pm</a><br /><br />calculations overflow/underflow<br />http://www.adobeforums.com/cgi-bin/webx/.3bbeb7e0<br /><br />FormCalc error-arithmetic overflow/underflow<br />http://www.adobeforums.com/cgi-bin/webx/.3bbc15f3

    Your error message indicates your script is being executed as FormCalc, not JavaScript.
    If you're using FormCalc try using an If statment to test for zero/null.
    if (tr>0) then (ac/tr)*100 endif

  • #Error using IIF and divide by zero

    I am getting an error in a calculated field that could potentially divide by zero, even though I'm using an IIF.  The column displays in the report as "#Error".  My expression looks like this:
    = IIF(Fields!Qty.Value = 0,
    "None", Fields!Hours.Value / Fields!Qty.Value)
    I have successfully used this approach with INT fields, but this time the Hours field is a NUMERIC(9,2).  My workaround is to do this:
     IIF(Fields!Qty.Value = 0, "None", IIF(Fields!Qty.Value = 0, 42, Fields!Hours.Value) / Fields!Qty.Value)
    I guess the 42 is cast to an INT inside the second IIF and the calculation works.
    What's strange is that the division would even be carried out in the event of Qty = 0 from the first IIF, because the expression should just evaluate to "None" and that would be that.
    Has anybody run into this problem?  Is my workaround the recommended approach?
    -Larry

    First a diatribe: This is just one of the many annoying "features" of SSRS that needs to be fixed. It should just flat out work. Period.
    Now the fix.
    The following formula to calculate Discount% gives the #Error result if List = 0
    =iif(Fields!List.Value=0,0, (Fields!List.Value-Fields!Net.Value)/Fields!List.Value)
    However, if you add a very small number to the divisor it will work.
    =iif(Fields!List.Value=0,0, (Fields!List.Value-Fields!Net.Value)/(Fields!List.Value+.000001))
    Apparently SSRS evaluates the false part of the expression before it tests. Try this in most any other language and you will not have this problem.
    You just need to add a small enough number to your formula to not impact your results when the divisor is not zero.
    You can actually leave out the IIF entirely if you do this:                             
    Fields!List.Value-Fields!Net.Value)/(Fields!List.Value+.000001)
    I usually leave the syntax in there just so I know what the intention was.

  • Divided by zero error

    All,
    I am having trouble with one of the reports in EBS.
    When I run the two underlying sql of the report in toad I get the data.
    But, when I ran the report from the application I was getting some oracle error.
    So, I ran the report directly from the reports builder to see what error I am getting.
    It turns out that I am getting divided by zero error.
    I am passing in the org id and gl dates an inputs the report.
    Please help me debug the report.

    Could you check if your report has any subquery that doesn't return any record when the parameters are submitted at run time.
    I had the issue in Crystal Reports where it threw a divide by 0 error.

  • SQL to avoid Dreaded "Divide by Zero" error

    Hey,
    I have been banging my head off the decode and NVL functions to avoid the divide by zero error, can tfor the life of me get it.
    2 columns, a & b.
    Need to get: a/b (but the whole thing fails if either is null or zero)
    Any help greatly appreciated.
    Dob

    VG2 wrote:
    You need something like
    decode( b, 0, to_number(null),
    b, null, to_number(null),
    a/b )What is that?
    in psuedo language with that statement you are saying...
    If b is zero then return to_number(null) (which is the same as null) else
    if b is null then to_number(null) (which is still null) else
    a/b
    surely it's just a case of saying
    nvl(a,0)/nvl(b,1)which assumes that if b is null it should not effect a and if a is null then the result should be zero.

  • Help: Divide by Zero Errors

    Hi, can someone please advise me on how to avoid script failure alerts (like the one below), which are generated because certain calculations are being performed before any positive value has yet been set in a numeric field?
    Here is an example of the calculation:
    --- form1.SF_CalculationTable.acview[0]::calculate - (FormCalc, client) --
    (ac[0] / tr[0]) * 100
    Error example:
    Script failed (language is formcalc; context is
    xfa[0].form[0].form1[0].SF_CalculationTable[0].acview[0])
    script=(ac[0] / tr[0]) * 100
    Error: arithmetic over/underflow.
    update: it appears these erros are "divide by zero" errors.
    So my questions are,
    (1) would I put any javascript (to override the zeros) on the "validate" event or the "calculate" event, and on which of the three fields in question, acview[0] (the result), tr[0] (the denominator) or ac[0] (the numerator). and...
    (2) What might that javascript look like?
    Harry

    Your error message indicates your script is being executed as FormCalc, not JavaScript.
    If you're using FormCalc try using an If statment to test for zero/null.
    if (tr>0) then (ac/tr)*100 endif

  • Roxio "divide by zero" error

    I have printed a dozen or so DVDs using my HP 5200 series printer and the same ink-jet printable DVDs that I'm now trying to print to.  Now when I try to print I am getting a "divide by zero" error message and the software locks up.  The only way to regain control of the computer is touse task manager to shut the Roxio software down.  After restarting several times with same results I uninstalled/reinstalled the software from the HP installation CD and still am getting the error.
    First question is if someone has found a fix.  Second question is of someone has found good software for printing to discs usint the 5200 series printers.  I'm not satisfied with the Roxio product and certainly won't upgrade from the free version if I can't get it working.  I have Nero 7 but I don't believe it will work for printint directly to disc using the 5200 series printers.

    i'm having the exact same problem with the labeling software..... i would greatly appreciate an answer to this spoof-auf. i'm using 3.2.1.28 express  .... 

Maybe you are looking for