Rounding to 2 decimal places WITHOUT using any formatting class

Hello
I'm trying to round a number (double) to 2 decimal places without using any of the formatting class like (DecimalFormat or Math.Round and BigDecimal). Is it possible to do it by just using typecast?

OP:
BigDecimal is not a formatting class. Math.round isn't a class at all.
Typecasting doesn't really do that sort of thing at all (unless you count dropping fractional components when casting to an integer type).
double holds values in binary format, so it's basically impossible to round to decimal values meaningfully.
Chuck:
I thought that BigDecimal supported arbitrary decimal precision, so one doesn't have to do that sort of thing....?

Similar Messages

  • Double value truncated to two decimal places without rounding the value.

    I want to truncate double value to two decimal places without doing the rounding of the value.
    Is there any method which can directly do the truncation.

    There's many ways to achieve this such as using
    BigDecimal's setScale method or type-casting. This is
    the way I like to do it:double d = -5.239;
    d = d > 0 ? Math.floor(d * 100) / 100.0 : Math.ceil(d
    * 100) / 100.0;
    Your division by 100 may cause an rounding error, because there are numbers which no finite binary representation. That's splitting hairs! I know ;-)

  • Can i make a book in iPhoto without using any of the built in layout templates, which are too limiting when i have already cropped my pictures to show just what I want. Ideally I just want to drag and drop and arrange and size the pictures myself

    Can i make a book in iPhoto without using any of the built in layout templates, which are too limiting when i have already cropped my pictures to show just what I want. Ideally I just want to drag and drop and arrange and size the pictures myself

    If you have Pages you can create customs pages for your book as TD suggested. If you have Pages from iWork 09 or 11 this app will add 80 or so additional frames to those offered:  Frames and Strokes Installer. Don't use it on the latest Pages version, however.
    This tutorial shows how to create a custom page with the theme's background: iP11 - Creating a Custom Page, with the Theme's Background for an iPhoto Book.  Once the page is complete to get it into iPhoto as a jpeg file follow these steps:
    Here's how to get any file into iPhoto as a jpeg file:
    1 - open the file in any application that will open it.
    2 - type Command+P to start the print process.
    3  - click on the PDF button and select "Save PDF to iPhoto".
    NOTE:  If you don't have any of those options go to Toad's Cellar and download these two files:
    Save PDF to iPhoto 200 DPI.workflow.zip
    Save PDF to iPhoto 300 DPI.workflow.zip
    Unzip the files and place in the HD/Library/PDF Services folder and reboot.
    4 - select either of the files above (300 dip is used for photos to be included in a book that will be ordered).
    5 - in the window that comes up enter an album name or select an existing album and hit the Continue button.
    That will create a 200 or 300 dpi jpeg file of the item being printed and import it into iPhoto. For books to be printed choose 300 dpi.

  • Rounding to 2 decimal places in Derived column transform editor

    I want to replace the contents of a value column with itself but rounded to 2 decimal places.
    The current column is a double and I have tried to perform this using the following expression but it fails to work.
    Code Snippet
    Round(cc_vl,2)
    How should I achieve this?

    I’ll take a guess here but you started with this –
    123.45678
    Got this –
    123.45000
    Wanted this –
    123.45
    So the 123.45000 is absolutely correct, the value has been rounded to 2 digits. A double however has a scale greater than 2, and you only wanted two digits after the point because you were concerned about how the value looked rather than the actual value. This is certainly not a bug. It is how you format the data for display.
    Your solution is the way to do this, either on the Derived Column or Data Conversion Transformation. You got it in the end, the replace versus new, because you cannot change the type of a column. You may convert the value, but the storage type of the column means it will implicitly revert to the base column type when you put it back, albeit with a value that has been rounded.
    Does that explain it?

  • Rounding to 2 decimal places

    When using Math.round, I know to round to 2 decimal places it would be Math.round(variable * 100.0)/100.0. I have this in one program and it works. (answer = Math.round(answer*100.0)/100.0;) I have it in another program and it doesn't (double answer = Math.round(balances [looper]*100.0)/100.0;// balances is declared as double balances [] = new double [numberOfCustomers];) What am I doing differently that I should be looking for.

    Hi,
    Please try using java.text.DecimalFormat class. This class is a subclass of java.text.NumberFormat. You can read about this class from JDK documetation.
    HTH
    VJ

  • Is it possible to retrieve photos from an iPod Touch 5th Generstion iOS 7 backup to iTunes on a MacBook, without using any other iDevice?

    Is it possible to retrieve photos from an iPod Touch 5th Generation iOS 7 backup to iTunes on a MacBook, without using any other iDevice?
    I Backed up my iPod Touch 5th Generation iOS7 onti my MacBook using iTunes
    Later, I lost the iPod.
    I want to retrieve as much of the data, especially photos, as possible ftom the backup.
    I do not have another iPod to use the restore function.
    Is there any other way to retrieve the photos or any other data from the backup?

    You could restore an iPad or iPhone from the backup.
    Some of this apps are compatible with a Mac
    How to perform iPad recovery for photos, videos
    Wondershare Dr.Fone for iOS: iPhone Data Recovery - Wondershare Official     
    http://www.amacsoft.com/ipod-data-recovery.html

  • I need to get 2 decimal places when using a formula for a quotient and Numbers will only give me whole integers which is useless since most items will be less than 1. How can I change this?

    How do I get 2 decimal places when using a formula for a quotient? It only gives me whole integers. Most of the results will be less than 1 so I need 2 decimal places

    the quotient function returns only whole number portion of the dividing two numbers.  If you want the actual decimal value use the divide operator.  you enter this as:
    A/B
    if the numerator is in A1 and the denominator is in B1 you can enter the formula like this:
    =A1/B1

  • How to create a popup window to load HTML page in AIR application without using any mx or spark?

    How to create a popup window to load HTML page in AIR application without using any mx or spark components?
    I need to load the HTML page in popup in AIR application without using any of the <mx> or <spark> components. I need to open in the application itself not in the browser.(If we use navigateToURL() it will open in th browser)

    Can we achieve this? can somebody help me on this scenario..

  • I have a macmini on order, I wonder if I can pair the wireless apple keyboard and magic touchpad without using any other input devices, especially, since everything is brand new and not yet paired.

    I have a macmini on order, I wonder if I can pair the wireless apple keyboard and magic touchpad without using any other input devices, especially, since everything is brand new and not yet paired.

    You may just want to save yourself any possible issues
    by just hooking up a wired keyboard and mouse on first
    start up.  Any USB keyboard and mouse should work.
    There have been many that have had problems on first boot
    using the Bluetooth devices. 

  • Length of a string without using any built-in functions

    code that returns the length of a string without using any built-in functions.
    thanks
    Sam

    A string is internally represented by a character array.  An array of characters will reside on the stack, not the heap.  Yes, we always learned that String is a reference type, but what goes on in your memory might still surprise you...
    A struct is internally represented by only it's private properties, sequentially on the stack.
    So basically, what I thought is happening by messing with the structlayout: is only tricking our programming a bit into thinking that the top X bytes on the stack represent a chararray, while actually we put them there as a string.
    Wrong. True. And wrong.
    A string is internally represented by, in that order, an array length, a string length, the chars. None of them resides on the stack.
    An array is internally represented by, in that order, an array length and the chars. None of them resides on the stack.
    When you use the FieldOffset attribute to handle the string as a char array, you don't get anything right:
    - the Length returned is the "array length" of the string, which is equal to the string length + 1.
    - the chars returned by the array indexer are shifted by 2 chars (the length of the "string length" field).
    You can use the FieldOffset to make that work, but it needs a little bit more work.
    unsafe static int Test()
    string myString = "This string may contain many string inside this string";
    string testString = "string";
    int countResult = 0;
    fixed (char* myChars = new StringToChar { str = myString }.chr, testChar = new StringToChar { str = testString }.chr)
    // The 2 first chars of the array are actually the string length.
    int myCharsLength = myChars[1] << 16 | myChars[0];
    int testCharLength = testChar[1] << 16 | testChar[0];
    for (int i = 0; i < myCharsLength - testCharLength + 1; i++)
    if (myChars[i + 2] == testChar[2])
    for (int j = 1; j < testCharLength; j++)
    var c = testChar[7];
    if (myChars[i + 2 + j] != testChar[j + 2])
    goto endOfCharAnalyses;
    countResult++;
    endOfCharAnalyses:
    continue;
    return countResult;

  • I am using Iphone 5s my battery is draining like anything. Without using any application also it seems i am using iphone 5s but in show only really i am using like previous nokia 1100 model.

    I am using Iphone 5s my battery is draining like anything. Without using any application also it seems i am using iphone 5s but in show only really i am using like previous nokia 1100 model.

    Are there apps on your phone right now? 
    I think one of your apps is causing this.
    The only way to find out is to delete them all and then add them one by one to see what app maybe causing this.
    Especially if you've gone thru 3 iphones already.
    When you restored as new - did you sync back your stuff - apps/music or did you restore from backup?

  • How to do Indepth table analysis without using any tool

    Is there anyway of indepth analysis of tables of a database without using any tool, i.e. by means of sql's, pl/sql's only.
    My database has around 800 main tables which have several other related relational tables(objects relating 2 tables on basis of OTO, OTM, MTO, MTM object relationship) and several dependent views(made from among the 800 base table only).
    Currently database is indexed, has joins and views, all in working scenario but yet do not gauranty consistent behaviour.
    My sole purpose is to analyse all main tables (around 800 of them) in my database by running scripts and prompt errors, warnings, exceptions wherever table needs indexing or change of joins(eg - from cross to inner,etc. ) or check inorder to avoid table full scan for related relational tables and dependent views.
    My databse is Oracle10g.
    Please do revert for any doubts.

    My sole purpose is to analyse all main tables (around 800 of them) in my database by running scripts and prompt errors, warnings, exceptions wherever table needs indexing or change of joins(eg - from cross to inner,etc. ) or check inorder to avoid table full scan for related relational tables and dependent views.There are no tools which can tell whether your table needs indexing or whether you need to change joins methods, by just looking at your database. At most, you can get an idea about the missing indexes in case of a parent-child relation. Everything else, falls under application tuning - which involves sql tracing, profiling etc.
    If you cannot trace individual sessions, then you are better off monitoring the database with statspack/AWR (if licensed). Generate reports at frequent intervals, look at the resource consuming SQLs and have a discussion with dev team to fix them, whenever possible.
    EM can also be used for SQL analysis.

  • Can we demodulate the signal recieved at DAQ card without using any hardware interface(by only using labview)?

    Hi all,
    Can we demodulate the signal recieved at DAQ card without using any hardware interface(by only using labview)? if yes then how? please give brief idea.
    Regards,
    Amit

    There is probably a way to do it, but it it may be easier to use an X-series board for the job.   They support a new counter capability for count reset on a digital edge without needing to be configured in encoder position mode.  I am not sure exactly how that feature's been implemented however, so maybe it won't make things easier after all.
    The plan based on the hoped-for behavior: 
    1. Configure an X-series counter for pulse generation based on "ticks" of your clock channel.
    2. Set both initial delay and low time to the critical # of ticks.
    3. Configure for count reset on a digital edge (if possible in pulse generation mode)
    4. Configure the count reset value to be the critical # (or possibly 1 less, if possible in pulse generation mode)
    5. If you want the output to remain high indefinitely, configure the counter task to use its own output as a
    pause trigger, and pause while high.
    The way pulse generation works is to preload a # of "low time" ticks into the count register.  Then every source edge will decrement the count.  When the count reaches terminal count (0), the counter's output is toggled (or can be configured to pulse).  The register is then loaded with the # of "high time" ticks and the process continues.
    You would be perpetually interrupting the count-down process as long as you got your triggers in time.  The count would keep getting reset to the # of low counts, keep decrementing toward 0 without reaching it, and so on.  If ever you did reach 0, the output state would toggle high, then the high state would prevent subsequent clock signals from decrementing the count.
    You can conceivably do a similar thing with a 6601, but I'm pretty sure you'd need 2 counters working together to get it working.
    -Kevin P

  • Help required to create portal without using any vendor specific API's

    Hi All,
    I am trying to develope a portal without using any vendor specific API or tool like Weblogic workshop or Vignette Wizard. I would like to know whether Sun Microsystem provides any API for developing portal. I would also appreciate if I can get few links for developing portal using java API's...
    Thanks in advance...
    Dgk

    Sure Sun provides the tools: it is called the compiler. Now all you need to do is write the code for a portal. But since there are vendor specific solutions available that could make your life a lot easier, writing one yourself is like reinventing the wheel.
    Pardon my mild sarcasm, but avoiding API's not developed by Sun is not the general idea behind the Java platform. You are encouraged to use those API's.

  • How do we Back up my music files from my phone into my computer (PC) without using any programs

    I am looking for a way to back up my Music from my iPhone into the computer (Like how the iPod Nano could) WITHOUT using any programs. Is there a way? Is it possible? If so, please help....
    thankyou
    Charlie

    Music purchased from the iTunes store can be redownloaded again for free (see.http://support.apple.com/kb/HT2519)  In other words, it's already in iCloud so there's nothing you need to upload.
    However, if you don't want to run into problems syncing with your new computer you need to copy the entire iTunes folder (not just the music folder) from your old computer to your new one using one of the methods outlined here: http://support.apple.com/kb/HT4527.

Maybe you are looking for

  • How can I print an address card?

    Hi Folks, I've just discovered what seems like a ridiculous limitation of Address Book. I am having a hard time believing this is so, and am sure there must be a way to do this. I need to print out an address card, as it appears in the Address Book.

  • Damaged image file

    I'm trying to copy an iPhoto library using the Finder, and keep getting the following error message: The finder cannot complete the operation because some data in "IMG_2255.CR2" could not be read or written. (Error code -36) I've tried searching for

  • Where is my UDF?

    Hi brothers, anyone can help me? How can i get the correct UniqueUID of an UDF from a system or a user form? I have seen something like this: oUDF = SBO_Application.Forms.GetForm( -m_SboForm.Type, m_SboForm.TypeCount); ... but this code is not safe.

  • I can't copy/paste text in itunes?

    I use Windows 7, and the latest itunes. I dont have any addons or anything either. So, for some reason I can't use the copy/paste function in itunes. I listen to foreign music and when I want to copy the names of songs or artists and paste them into

  • Little white dialog boxes - no data.

    I'm getting little white dialog boxes all the way across the screen that contain no data when using Safari. They can be closed and expanded and seem to appear infrequently. Any idea what they are? Thank you for responses.