BigDecimal, division method and Rounding
I want guys to check out my observation of the BigDecimal and comment on which is really the best way of working around with the class instead of using double or float. The particular emphasis is on BigDecimal division method.
I posted a test class to drive my point
import java.math.BigDecimal;
import java.math.MathContext;
* @author m-enudi
public class BigDecimalDivideTest {
public static void main(String[] args) {
BigDecimal first = new BigDecimal(10f);
BigDecimal second = new BigDecimal(1000f);
BigDecimal result1 = first.divide(second, BigDecimal.ROUND_CEILING);
BigDecimal result2 = first.divide(second, BigDecimal.ROUND_DOWN);
BigDecimal result3 = first.divide(second, BigDecimal.ROUND_FLOOR);
BigDecimal result4 = first.divide(second, BigDecimal.ROUND_HALF_DOWN);
BigDecimal result5 = first.divide(second, BigDecimal.ROUND_HALF_EVEN);
BigDecimal result6 = first.divide(second, BigDecimal.ROUND_HALF_UP);
BigDecimal result7 = first.divide(second, BigDecimal.ROUND_UP);
BigDecimal result8 = new BigDecimal(first.doubleValue() / second.doubleValue());
BigDecimal result9 = first.divide(second, MathContext.DECIMAL128);
System.out.println(" >>>>>>>>>>>>>>>>>>>>>>> " + result1);
System.out.println(" >>>>>>>>>>>>>>>>>>>>>>> " + result2);
System.out.println(" >>>>>>>>>>>>>>>>>>>>>>> " + result3);
System.out.println(" >>>>>>>>>>>>>>>>>>>>>>> " + result4);
System.out.println(" >>>>>>>>>>>>>>>>>>>>>>> " + result5);
System.out.println(" >>>>>>>>>>>>>>>>>>>>>>> " + result6);
System.out.println(" >>>>>>>>>>>>>>>>>>>>>>> " + result7);
System.out.println(" >>>>>>>>>>>>>>>>>>>>>>> " + result8);
System.out.println(" >>>>>>>>>>>>>>>>>>>>>>> " + result9);
System.out.println(" >>>>>>>>>>>>>>>>>>>>>>> " + (first.doubleValue() / second.doubleValue()));
}Try working with test samples like
first = 129.0494
second = 39484.111
I did not try to use the BigDecimal.ROUND_UNNECCESSARY because it always caused the ArithmeticException.
can you guys comment on the best way of doing division with the BigDecimal class.
For now I seem comfortable with using the MathContext approach, though not in anyway an authority in the use of the class.
Regards
This result changed significantly with a change in code as listed below:
BigDecimal result1 = first.divide(second, 2, BigDecimal.ROUND_CEILING);
BigDecimal result2 = first.divide(second, 2, BigDecimal.ROUND_DOWN);
BigDecimal result3 = first.divide(second, BigDecimal.ROUND_FLOOR);
BigDecimal result4 = first.divide(second, BigDecimal.ROUND_HALF_DOWN);
BigDecimal result5 = first.divide(second, 2, BigDecimal.ROUND_HALF_EVEN);
BigDecimal result6 = first.divide(second, 2, BigDecimal.ROUND_HALF_UP);
BigDecimal result7 = first.divide(second, 2, BigDecimal.ROUND_UP);
BigDecimal result8 = new BigDecimal(first.doubleValue() / second.doubleValue());
BigDecimal result9 = first.divide(second, MathContext.DECIMAL128);
Similar Messages
-
Flip Horizontal/Vertical and Rounded Corners Shortcut Keys
This is missing and annoying to do with the tool or the transform palette flyout. Pretty sure you can't even set your own shortcut within the program. Please add this standard.
In the meantime if you have autohotkey I made this script to map the alt menu to do it.
I've also added better blend shortcuts and rounded corners.
^ means control
+ means shift
! means alt
; means comment
#IfWinActive ahk_class illustrator
;Create Blend
^b::!^b
;Blend Options
^+b::Send !obo
;Roundcorners with preview already checked
^+r::Send !csr{tab}{space}{tab}{tab}{tab}
;FlipH
^+h::Send !otev{Enter}
;FlipV
^+v::Send !oteh{Enter}Thanks. You're right...unfortunately the bgcolor still bleeds
through. Check it out. Any ideas?
<cfform method="get" name="TestPanel" preloader="no"
format="flash" height="210" width="300" skin="haloblue" >
<cfformgroup type="hdividedbox" width="200" height="90"
visible="yes" enabled="yes"
style="cornerRadius:15;BorderStyle:roundCorners;borderThickness:1;backgroundColor:##E5E7F E;">
<cfformgroup type="horizontal">
<cfformgroup type="vertical">
<cfformitem type="text" >Test</cfformitem>
<cfformitem type="text" >Panel</cfformitem>
</cfformgroup>
</cfformgroup>
</cfformgroup>
</cfform> -
How do I Average two fields and round down?
I need to average two fields and round down to the nearest whole number. The two fields will always each have a value.
If someone could help me out, I'd appreciate it.
T.Assuming you want this to be a custom calcuation script for a field, it could look something like this:
// Custom calculation script
(function () {
// Get the field values, as numbers
var v1 = +getField("text1").value;
var v2 = +getField("text2").value;
// Set this field's value to the average, rounded down
event.value = Math.floor((v1 + v2) / 2);
More information on the Math.floor method can be found in any decent JavaScript reference. -
Issue in MODVAT Clearing Account and Rounding off of Excise.
I have one issue in MODVAT Clearing Account and Rounding off of Excise.
Example:
Material cost 100Rs.
Excise value
1. BED 10.5 Rs
2. ECes 2.1 Rs
3. HEces 1.3.Rs
At the time of GR
Material Ac Dr 100
To GR/IR 100
At the time of Excise Capture
We done the rounding of Excise value
RG23 A BED 11
RG23 A Eces 2
RG23 A HEces 1
To MODVAT 14
At the time of IR . System create IR with reference of PO
GR/IR DR 100
MODVAT 13.9
To Vendor 113.9
So here you can see that there is a difference of 0.1 in MODVAT account and hence we are crediting Vendor with the lesser amount here with 0.1 RS.
So we cannot reconcile the MODVAT Account
Less Payment to vendor by 0.1 Rs
So is there any solutions on that.
regards
Shayam
Edited by: Shayam_210 on Jan 3, 2011 7:08 AM
Edited by: Shayam_210 on Jan 3, 2011 7:09 AMHi,
Check the rounding setting in below:-
SPRO > Logistics - General > Tax on Goods Movements > India > Basic Settings > Maintain Company Code Settings
SPRO > General Settings > Currencies > Define rounding rules for currencies
Regards,
Gaurav -
How to create the custom method and make it available to clients:
Hello, Can any one help me with this problem ASAP??
I am trying to work on an example of "Customizing the Query and Creating an Associated Custom Method"
from http://helponline.oracle.com/jdeveloper/help/topics/jdeveloper/developing_mvc_applications/adf_pviewcustommethod.html?tp=true#method. To do that, the first task is to create the custom method and make it available to clients.
Following instructions in the helponline documentation, I completed the three steps: (1) "Specify a custom query for the View Object definition for EmployeesView", (2) "Add the custom method to the application module Java class", and (3) "Make the method available to clients".
The following is the error message I got to test the application module. Can anyone tell me what the message really means and what I should do. I am wondering if there is any mistakes in the document.
(oracle.jbo.SQLStmtException) JBO-27122: SQL error during statement preparation. Statement: SELECT Employees.EMPLOYEE_ID, Employees.FIRST_NAME, Employees.LAST_NAME, Employees.EMAIL, Employees.PHONE_NUMBER, Employees.HIRE_DATE, Employees.JOB_ID, Employees.SALARY, Employees.COMMISSION_PCT, Employees.MANAGER_ID, Employees.DEPARTMENT_ID FROM EMPLOYEES Employees WHERE Employees.SALARY > :1 and Employees.DEPARTMENT_ID = :2
----- LEVEL 1: DETAIL 0 -----
(java.sql.SQLException) ORA-01008: not all variables boundYou need to set values for the parameters in your query before you try to execute the query in the view object.
So you need to call the setBindVars method before the query. -
Session method and call transaction methos which one is the sap recomonded
hi
PLease give me the answer to these questions.
session method and call transaction methos which one is the sap recomonded why .
2) if we want to maintain BDC program in all the systems.wt to d0Hi Revethi,
Here is the difference between the Session and Call Transaction method.
Session
Session method supports both small amount of data aswell as large amount of data
2) data processing is asynchronus and data updation is synchronus.
3) it process multiple apllication while perfomaning validations.
4) in session method data will be updated in data base only after processing session only.
5) system provide by default logfile for handling error records.
6) it supports both foreground aswell as background process
in bdc we use FM ... bdc_open_group " for creating Session
bdc_insert " adding transaction and bdcdata table for updating database
bdc_close_group " for closing Session
Call Transaction
Call transaction exclusively for small amout of data
2) it supports only one apllication while perfoming validations
3) there is no default logfile, We can explicitly provide logic for creating logfile for handling error records.
we can create logfile by using structure....BDCMSGCOLL
4) it doesn't support background processing.
5) data processing is synchronous and Data updation is Synchronous( default), in
this method also supports daya updation in asynchronus process also.
Syntax:
Call transaction <transaction-name> using BDCDATA
mode <A/N/E> update <L/A/S>
messages into BDCMSGCOLL. -
Whats the difference between a class method and a instance method.
I have a quiz pretty soon and one of the questions will be: "How does an instance method differ from a class method." I've tried looking this up but they gave me really complicated explanations. I know what a instance method is but not really sure what a class one is. Can someone post an example of a class method and try to explain what makes it so special?
Edited by: tetris on Jan 30, 2008 10:45 PMJust have a look:
http://forum.java.sun.com/thread.jspa?threadID=603042&messageID=3246191 -
My ipod Touch does not want to turn on. I've tried all the different methods and I'm stuck and dont know what to do now. What else can I try?
JesusDGZ wrote:
My ipod Touch does not want to turn on. I've tried all the different methods and I'm stuck and dont know what to do now. What else can I try?
I have no clue what you mean by "all the different methods." Here are my suggestions.
First, try a system reset. It cures many ills and it's quick, easy and harmless...
Hold down the on/off switch and the Home button simultaneously until you see the Apple logo. Ignore the "Slide to power off" text if it appears. You will not lose any apps, data, music, movies, settings, etc.
If the Reset doesn't work, try a Restore. Note that it's nowhere near as quick as a Reset. It could take well over an hour! Connect via cable to the computer that you use for sync. From iTunes, select the iPad/iPod and then select the Summary tab. Follow directions for Restore and be sure to say "yes" to the backup. You will be warned that all data (apps, music, movies, etc.) will be erased but, as the Restore finishes, you will be asked if you wish the contents of the backup to be copied to the iPad/iPod. Again, say "yes."
At the end of the basic Restore, you will be asked if you wish to sync the iPad/iPod. As before, say "yes." Note that that sync selection will disappear and the Restore will end if you do not respond within a reasonable time. If that happens, only the apps that are part of the IOS will appear on your device. Corrective action is simple - choose manual "Sync" from the bottom right of iTunes.
If you're unable to do the Restore, go into Recovery Mode per the instructions here. -
so my Ipod touch hasn't been connecting to computer, nor charging for a week or two until i turn it off completely and now i try to reset all content and setting,(thinking it may connect to the computer and itunes and also charge) but the circle goes round and round for like hrs(24) and it still does not complete the reset.
pls pls pls pls help .
i have tried alot of solutions, but non of them have worked.Have you tried walking it into the nearest Apple Store and asking for assistance there...?
I'm guessing you don't have Apple Care on it. -
I plug my iphone 3gs into my laptop and it no longer syncs with my iTunes. I've tried all the trouble shooting methods and nothing works. My iPhone doesn't appear on iTunes or under "My Computer." Does anyone know how to fix this?
If AMDS is running, you are using a USB port directly on the computer and not a hub, you have disconnected other USB devices except keyboard and mouse, you have completely uninstalled and reinstalled iTunes as described in http://support.apple.com/kb/HT1925, You have tried cleaning the connector on the bottom of the phone, you have tried a different cable, you have installed the latest USB drivers for your computer, you have disabled your antivirus and firewall, you are running as an Administrator account and you have tried creating a new user on your computer and connected when logged in as that user then you have exhausted my knowledge. The only other thing to try is a different computer. If it isn't recognized on a different computer you have a hardware problem. Good luck!
-
I'm moving to an imac from a PC. I want to move my itunes library from the PC to my new imac. What is the best method and where can I find instructions?
Move iTunes from PC to MAC, http://www.macworld.com/article/146958/2010/03/move_itunes_windows_mac.html
-
Hi
I'm trying to update my apps using the creative cloud desktop app. I can't see any apps in the app tab, the wheel just spins round and round and nothing happens. Has anyone got any ideas? I've tried uninstalling the desktop app and reinstalling but it still has the same problem.
Cheers
RachelHi Rachel,
You can follow the article: App doesn't open | Progress wheel spins continually to get your issue fixed.
Let us know if the issue still persists or not.
Regards,
Ratandeep Arora -
Where can i find the method and property reference?
hello,
i am now writing ActivX for C++ and LabView ( as container). However, I cant find the detail description of all properties and methods of the exported class from LabView. Can you suggest me some reference of it? thanks so much of it!
CowCowHello
Open up The LV Help and goto the search tab to look for ActiveX Server Virtual. You should find a page called ActiveX Server Virtual Instrument Class Properties and Methods. This lists all the methods and properties of the Virtual Instrument object.
Bilal Durrani
NI -
When I open iTunes on my iPad and tap on purchased for music, the timer just goes round and round and won't find my purchased tunes and I can't therefore download any new items I have bought. Any suggestions on how to reload the software?
Make sure you have a good wifi connection.
Make Sure iOS is updated to the latest version
Reboot the device by pressing and holding down the home and sleep/wake buttons (power) at the same time until the apple logo appears on the screen, then let go.
If that doesn't work then reset the device by going to settings/general/reset/reset all settings -
How to find out the public methods and public fields available
Hi,
I have a dll for which to use it, i need to know the methods and the fields available for public use. Is there anyway to find out that information using any tool. I dont have any literature about the dll. Only have that dll.
Thanks in advance,
-Madhuri.You can find an article about creating the methods on the Microsoft Developement Network call "How to Create 32-bit Import Libraries Without .OBJs or Source"
However that is only part of the problem.
Consider if you find that the dll has a function like this:
InitApplication(char*, int, char, long);
What do you put in for each of those parameters? The only way I know to do that it to use a debugger and step through the assembler code figuring it out as you go. Alternatively you buy or find a disassembler - C code would probably be easier to figure out.
I would also seriously suggest finding some different lists/news groups than this one. The topic has nothing to do with java. So you are likely to get better help somewhere that is more specific - like one of the MS lists.
Maybe you are looking for
-
17" imac looks and game performance
Hi All, Im thinking about getting a intel iMac for home, but Im not sure I can stretch to the 20" I remember thinking the 20" g5 imac was much better looking than the 17" because the area bellow the screen seemed more in proportion. Does the 17" inte
-
Using MacMini (2006) with CRT television
Hi all. I've been a mac owner for a while now, and decided to purchase a MacMini the other day to use connected to my tv using front row and eye tv. I have a Sony 32inch widescreen CRT tv. With the Mini I purchased a DVI to Video adapter and hooked i
-
Hi All, How to keep more than one reason code items in incoming payment ? . Basically I want to push the clearing difference to more than one account ( Material defective,Shipping problems etc.,for the paymnet diff) (Points will be allotted ) Thank
-
Mountain Lion on Macbook Pro ('08) - OS freezing - Should I revert to Lion?
Hello - I have an '08 Macbook Pro (the first one that used swipe gestures) that I recently updated to Mountain Lion from Lion. My computer worked fine for about a week but recently developed a concerning issue - the screen freezes and does the window
-
Buying iPod Classic in UK for foreign user.
I would like to buy an iPod classic in a UK retail store, but the computer/itunes account that will use the iPod will be foreign (EU), will it work? If so what about the warranty and are there other things to keep in mind?