The large int. Division

Hey guys,.

I'm bit stuck on a single division operation. Basically my application downloads a video from the web server, and I create a GaugeField to display the download progress. However when I try to do simple division on large integers it always gives me a result of 0.

I think this may have something to do with the fact that the numbers are so great?

For example I want to do the surgery

int downloadPercent = (totalRead/len) * 100;

where in an int totalRead = 335872 instance (that's how much of the file has been downloaded)

and int len = 3554163 (this is the total size of the file)

Any help would be greatly appreciated.

Thank you

When you use arithmetic on integers, one should be careful about the order in which expressions are evaluated. You wrote it, the compiler first evaluates totalRead / len. Assuming that totalRead is less than len, this will result in zero. The compiler will then multiply this by 100 0 and get 0. Just reformat the line as follows:

int downloadPercent = (totalRead * 100) / len;

I suggest (respectfully) that you do not follow the advice of the other answer. Floating-point best avoided, unless absolutely necessary, and it is not necessary in this case.

Tags: BlackBerry Developers

Similar Questions

  • OutOfMemoryError come when discovers the large image (2048 * 1024) and 89 KB

    Hello

    Please someone help me solve my problem of "OutOfMemory" coming in my Strøm BB device while I don't want to see the size of the large image. The size of the image that I use is about 89Ko and 2048 x 1024 px.

    I could see the image that is 140 kb and 1024 x 768 px, but not for 89 KB and 2048 x 1024 px.

     

    Here is my code to see the picture: -.

         

           public static Bitmap getBitmapFromUrl (String photourl) {}
    Bmf bitmap = null;
    data Byte [] = null;
    try {}
        
    FileConnection fconn = (FileConnection) Connector.open (photourl, Connector.READ_WRITE);
    java.io.InputStream entry = fconn.openInputStream ();
        
    ByteArrayOutputStream Baos = new ByteArrayOutputStream();
    int j = 0;
    While ((j = Input.Read ())! = - 1) {}
    Baos.Write (j);
    }
                
    data = baos.toByteArray ();
               
    Baos = null;
    Input.Close ();
    fconn. Close();
    entry = null;
    fconn = null;
                
    BMF = Bitmap.createBitmapFromBytes(data,0,data.length,1);<-- at="" this="" step="" i="" am="" getting="" the="" outofmemory="">

    data = null;
            
    } catch (Exception e) {}
    System.out.println ("Exception getBitmapFromUrl() DeleteIndividualPhoto :"); ")
    }
    return the bmf;
    }

    Thank you

    TEJ

    My understanding is that a Bitmap is a full image, uncompressed, and the Blackberry uses 2 bytes per pixel to represent the color, then the image of 2048 * 1024 means about 4 MB of storage.  It's not bad, especially since I suspect that you have more than one of them.  And of course the follow-up to this question is how you view this image size on the device?  Seems to me that this file size is a bit of an overdose.  But even if you don't need it, have you considered using the scale parameter of

    Bitmap.createBitmapFromBytes

    scaling of the image according to a more reasonable size before you create the Bitmap image?

  • updated 7.3 to 10.0.1 on iPhone iOS 5 in the messages, I can't put the phone in a horizontal position in order to enlarge the keyboard more. a field opens with the font script styles and I can't get off my screen, to get at the larger keyboard.

    I just upgraded my iPhone iOS 5 7.3 iOS 10.0, now when I use my e-mail, I can place my phone horizontally to get the larger keyboard is no longer and use my thumbs (many more fast typing). Now, I get a "field" with scripted, for styles to close since fonts. There is an icon of a 'keyboard' if I type nothing happens. Clues? your help will be greatly appreciated.

    Bill

    Pressing this icon small keyboard should work (done on my iPhone 7). Until someone answers with more information, another thing you could try is to open the keyboard when the phone is vertical and then put it too horizontal.

  • After you have reinstalled Th 38 (due to a problem of XPCOM), it now opens, but the large windows is stuck to one that opens with the name of the account.

    I think that Th 38 was the reason why my computer did not open at the total. Once that has been fixed, Thunderbird does not open more (error: XPCOM). After you have reinstalled Th 38 now I can open it and it looks good with the left pane, but the large window on the right is glued to that shows when you click on the name of the account (top folder in the left pane). None of the folders work, and none of the tabs on top of the page or the other. The only things that work are the links in the large window. I can see and open your messages by searching in the Inbox, for example. Would be grateful for any help!

    Looks like the problem is solved! I was appalled when I saw how many emails I had stored and deleted a large number of them. Then after restarting the computer, everything seems to be back to normal! Praise be to God! Too, Firefox seems to be back to normal after that I did a cleaning.

    Thanks anyway!
    Greetings from AngieP

  • How can I get rid of the large message on my screen of e-mail about Thunderbirdd birthday?

    The large message covers the bottom of my screen. Thanks for your help!

    The easy answer is to click on one of your messages, and the message text will replace the Start Page in the messages pane.

    If you want that he spread ever to go to the Menu bar and select Tools-Options-general and uncheck the option to display the Start Page.

    No menu bar display? Press the ALT key.

  • To work with the text to the assignment by the cursor of the large fragment of page it is necessary to change all the time down, 'against the judgment", but the page automatically does not start to rise upward, as happens in other browsers. I ask you for

    After the transition to Windows 7, there was a problem with Firefox. To work with the text to the award by the cursor of the large fragment of page it is necessary to change all the time down, 'against the judgment", but the page automatically does not ascend to the top as it was earlier, and like that occurs in other browsers. It is necessary to press the other key "down" which is him very troublesome. Resettlement on an earlier version (8.0) earlier irreproachably working, gave nothing. I ask you to help

    You must activate the module bar (Firefox > Options or view > toolbars;) CTRL + /) or find bar to make Firefox scroll the page while selecting the text (Ctrl + F).

  • After the update for Firefox 4, the font size in my gmails are smaller. I need to come back to the larger size. How?

    On both the gmails and the size of the font when gmails are open, the font size is less to before the upgrade to Firefox 4. I change all of the settings. I don't see where I can change this back to the large fonts. Help?

    The page may have been zooming. With Gmail on display are trying to use the hotkey Control + 0 (zero) to reset the zoom on the page.

    For more details on the use of the zoom on the page, see https://support.mozilla.com/kb/Page+Zoom

  • Satellite Pro A110 crashes during the transfer of the large data in LAN

    Hello

    My Satellite Pro A110 crashes during the transfer of the large data in LAN. The network driver is a Realtek RTL8139/810 x Family Fast Ethernet NIC I've been looking through this forum and found some wire whit exactly the same problem, saying that the solution is to update Realtek lan set up in BIOS, not the computer BIOS, but I can't find any link to download the necessary upgrade file. Can anyone tell me please where to find this upgrade file or send it to me directly?

    Thanks in advance

    Is - this transfer of data in the company where you work? Do you want to download data from the server, or how to understand this? How to understand what you mean under big data?

    Have you tried downloading data on the Internet? For example, if you try to download some trailer HD (more than 200 MB)?

  • The large paintings of calculation time

    Dear friends, dear LabVIEW developers,

    I'm trying to reduce the time of calculation for large bays. (In real life I'm eliminating unimportant vertices of a 3D mesh.)

    Migration from 8.6 to 2011 already has done a great job for me. And also I am pleased to run Windows 7 on a 64-bit computer.

    But, imagine a pointer-oriented language where you'd change an array element, you do not expect the computing time to change with the actual length of the table.

    Here, I work on a wide range of groups of array of length may be different (rather short, containing the indexes of the neighbors of my vertex).

    My problem is that I really don't see the reason why (I'm happy) the 100 times more slow performance when having a 100 times more great picture at hand for the fair value of the Exchange.

    Suggestions to work around to get the speed of the large paintings those comparable to small is greatly appreciated.

    Kind regards

    Jannis

    PS: I tried DataValueReferences but just the computing time to get 1 million references is almost an hour.

    Thank you guys!

    You were very good!

    Steven and Ben worked have been my brand of test bench has been poorly implemented, which Ben explained perfectly. This test has sent me the ghost hunting awaits the delay time for the large windows in the wrong place - the structure in Place.

    My next mistake was my local chaos with different versions LV and 3 PCs: Altenbach and Jeff are of course right about to maintain the constant size of matrix comes mark reduction in a separate meter. I did this at a time in a lost version later - and not a not spot the difference of between ArraySubset and DeleteFromArray the icon for a while...

    My time holes had to be hidden somewhere else. Thanks Ben, unfortunately those black dots of BufferAllocation are a bit small for my old eyes. Not know them at the end of the event and while loops!

    Each 15 seconds I actually shorten the big picture at its actual size to display it in the 3D graph. Now, here's the little interesting: ArraySubset actually redirect the memory at the end of the event and while loops, while DeleteFromArray only! I don't know who wrote somewhere, just not where easily see you...

    And to make it really bad: this allowance is probably made with each loop run little matter what this case has done - slowing of all stocks with it. (By the way: everything as a mem alloc comes even inside a case that is not running!)

    Once again thank you all. For me it's back to work after a very long-term wild-goose chase.

    Jannis

  • How can I remove the large green battery and plug icon?

    How can I remove the large green battery and plug icon? It seems pretty ugly and useless. There is already an icon of battery-plus-card used to determine the level of battery and charging status...

    Moderator edit: matched subject to content.

    Hi thang_nguyen!

    Another alternative is to double-click the battery icon and when Power Manager opens, click on Advanced Options > Options and uncheck the box "see the gauge of Power Manager in the bar then apply stains.

    To access the Lenovo Power Manager when the gauge of Power Manager is disabled, right-click on the Windows icon / energy from the battery in the bar of tasks and you should see "Power Manager".

    I hope this helps!

  • Memory management by displaying the large amount of data

    Hello

    I have a requirement to display the large amount of data on the front in table 2 & 7 graphic during the time period 100hrs for 3 channels, data read from strings must be written in the binary file, and then converted and displayed in front of the Panel for 3 channels respectively.

    If I get 36 samples after conversion for all hours, up to 83 h 2388 samples displayed in table and graphical data are thin and samples correspond exactly.

    After that 90 hours 45 minutes late is observed after theoretical calculation of samples, what could be the problem

    I have controller dual-core PXI8108 with 1 GB of ram

    As DFGray,

    says there is no problem with the RAM or display, problem with conversion (timming issue) if I am data conversion of large amount it takes even, compared to the conversion less amount of data. So I modifed so that each data point Sec 1 is convereted at once, problem solved

    Thanks for your replies

  • Want M7-K211dx: search for the larger battery

    I use Envy M7-K211dx.

    but the battery is too low. It's only 4 cells.

    So, I'm looking for larger battery, the cell of 6 or 8 cells or more.

    can you let me know the name of the model of the larger battery?

    Thank you.

    @Anderson_Kim_1

    Your 2 options.

    (19) 4-cell, 41 w/h, H 2. 8 a Li-ion battery 756743-001

    4 cells, 48 Wh, 2,3 AH Li - ion battery 756745-001

    Your Service Guide here.

    http://support.HP.com/us-en/product/HP-envy-M7-notebook-PC-series/7527539/model/7734388/manuals/

    REO

  • Formatted NTFS disks flash freeze computer during the transfer of the (large) files

    Let's first, I tried KB976972 and does not work for me, it actually returns to "the update is not applicable to your computer" (probably because I don't have an NVIDIA USB chipset).
    Also I don't know of any computer in the past, I a tailor-made with i7 box 3770 with 16g of RAM, I won't go into detail here because I had this problem with previous Office (also an i7 but first gen) so that pretty much excludes material. The OS of choice is Windows 7 64 bit.

    The problem occurs when I try to copy files on flash memory drives formatted in NTFS (or readers of thumb if you want) (large). Tested readers are all Verbatim with writing speeds on 10megs per second with a capacity of 8 to 32g. The copy process lance "strong" with the window showing whimsical speeds copies anywhere between 500 to .9g per second and abnormally fast progress bar fills. Who finally stops before the end, after what looks like no more than 10 seconds or more, the time when the computer crashes somehow. The core of the operating system seems to be working, I can switch apps, ctrl-alt-del (Nothing kills the CPU or the whole system right now BTW), all the work of gadgets Google desktop (monitors refresh as expected), but real-world applications are frozen and in fact, if I try to tinker with them they will eventually become "inadmissible." After some time (a full, if not minute more) resumes the copy process, and the whole system will become responsive again. However, if the file is large enough this episode of gel repeat several times until it is completed.
    While readers LED flash Flash normally and consistently throughout. There are no errors with the transferred files.

    The question is NOT triggered by the large transfers with several smaller files. For example if I copy a whole folder 5g with images, the process will be less than the normal surface of 100%, the reported speed will be credible (about 7 m/s), the computer cling not or anything like that. However, if I try a single file of 5g hang episode repeat 2 or 3 times.

    As I mentioned previously the material can't be at fault, the disks themselves work perfectly and normally if formatted FAT32 or exFAT so there may be a problem with them either. The problem is only manifest with structure of NTFS files AND large files.

    Any ideas will be appreciated. THX

    Hello

    I understand that you can not transfer large files via USB key.

    1. is the question confined to a particular file?
    2 have you tried with another USB drive?

    3. do you get an error message when you try to transfer?
    4 have you connected the USB even to another computer and check if you're able to transfer large files?

    I would suggest trying the following steps and check if it helps.

    Method 1:


    Try to convert the NTFS file system and check if you are able to transfer files.

    1. click on start
    2. type cmd in the start search box
    3. right click on cmd in the menu and choose Run as administrator.
    4. in the command line type convert /FS: NTFS

    Method 2:

    Uninstall all USB entries in Device Manager.

    1. click on START
    2. right click "Computer" and select "Properties".
    3. on the left side, click on Device Manager.
    4. expand the 'USB Bus controllers' category
    5. right click and uninstall all THE references listed
    6. restart your computer and check if it works.

    You can also see the following article for more information.

    Transferring files and settings: frequently asked questions

    http://Windows.Microsoft.com/en-us/Windows-Vista/transferring-files-and-settings-frequently-asked-questions

    I hope this helps.

    If the problem persists, I suggest you post with the required information and we will be happy to help you.

  • How to install the large data file?

    Anyone know how I can install large binary data to BlackBerry files during the installation of an application?

    My application needs a size of 8 MB of the data file.

    I tried to add the file in my BlackBerry project in the Eclipse environment.

    But the compiler could not generate an executable file with the following message.

    «Unrecoverable internal error: java.lang.NullPointerException.» CAP run for the project xxxx»

    So, I tested with a small binary file. This time, the compiler generated a cod file. but the javaloader to load the application with this message.

    "Error: file is not a valid Java code file.

    When I tried with a small plus, we managed to load, but I failed to run the program with that.

    "Error at startup xxx: Module 'xxx' has verification error at offset 42b 5 (codfile version 78) 3135.

    Is it possible to include large binary data files in the cod file?

    And what is the best practice to deal with such a large data files?

    I hope to get a useful answer to my question.

    Thanks in advance for your answer.

    Kim.

    I finally managed to include the large data file in library projects.

    I have divided the data file in 2 separate files and then each file added to library projects.

    Each project the library has about 4 MB of the data file.

    So I have to install 3 .cod files.

    But in any case, it works fine. And I think that there will not be any problem because I use library projects only the first time.

    Peter, thank you very much for your support...

    Kim

  • type of Blackberry support more large int. what? What is long int?

    type of Blackberry support more large int. what?  is this type of long int?  65536?


Maybe you are looking for