Division in java double variable.

Hi all
I have a simple query .I am using the following code in my java mapping.
Please follow the following java code
double d1 = 22058310.53;
System.out.println("Output Value = " + d1/1000);
This gives me an output
Output Value = 220583.10530000002
whereas the correct o/p should be 220583.1053
Can anyone pls provide a solution to get the correct result.
regards
NIlesh Taunk.

Hi Nilesh,
Use the following code to Divide by 1000 using BigDecimal class which is better than using decimal type.
  <b>BigDecimal num= new BigDecimal("22058310.53");
  BigDecimal result= num.movePointLeft(3);
  System.out.println("Output Value = " + result.toString());</b>
OR
  <b>BigDecimal num= new BigDecimal("22058310.53");
  BigDecimal result= num.divide(num,BigDecimal.ROUND_HALF_UP);
  System.out.println("Output Value = " + result.toString()); </b>
Hope this helps.
Regards,
Ananth

Similar Messages

  • How to store  double  variable in hash map

    i need to store double variable using hash map, but i cant able to store it
    my jsp coding contains
    double et=24,j=5;
    hm.put("stm",st);
    hm.put("etm",et);
    Generated servlet error
    C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\exam\org\apache\jsp\availability_jsp.java:752:
    put(java.lang.Object,java.lang.Object) in java.util.Map cannot be applied to (java.lang.String,double)
    hm.put("stm",st);
    ^
    how to overcome this problem
    thank u in advance

    double etme;
    etme = hm.getDouble("etm");
    i'm getting this error
    C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\exam\org\apache\jsp\editdel_jsp.java:85: cannot resolve symbol
    symbol : method getDouble (java.lang.String)
    location: interface java.util.Map
    etme = hm.getDouble("etm");
    ^
    how to solve it
    plz help me

  • How to access a JAVA Script variable in JSP Code

    How to access a JAVA Script variable in JSP Code. I have been unable todo this.
    Plz Suggest a way.
    Thanks
    Soumya

    try to do this code
    String s=request.getParameter("javascriptvariablename");

  • Returning/passing Java script variable/value to PL/SQL environment

    Hi,
    Can someone give me a sample code about how to return a Java script variable to PLSQL environment?
    for example, I have a javascript function that returns timestamp in milisecond, I then want to write PLSQL code to call this java script function and save its value in a number-typed plsql variable for further calculation, I dont know how the two scripting language communicate.
    Thank you very much
    Binh
    null

    This is quite simple.
    I assume that you are able to define html form side through pl/sql. Suppose your new pl/sql value is v_time then in the procedure that you write include one more statement
    htp.p('<Input type=hidden name="v_time" value="">');
    and also in the form invocation,
    htp.p('<form name=app method=post action="time_handler" onSubmit="return false;">');
    and to the end you must be having a submit
    to it attach a onClick function that calls
    simply our validate function..
    eg htp.p('<Input type=submit value="process"
    onClick="validate();">');
    Include in the head portion
    the following script using htp.p procedure
    function validate()
    app.v_time.value=<calculated value>;
    return app.submit();
    Hope this helps.
    Nat
    null

  • JAVA ENVIRONMENTAL VARIABLE AND PATH SETTINGS

    Hi all,
    I am having a pecuilar problem with java environment variables and setting the path.
    I am trying to install and check the instalation using some pre-provided batch commands from Open GTS.
    The error log is as below .
    ** Found 2 Error(s)!
    1) The 'PATH' environment variable points to the JRE, rather than the JDK.
       [Reason: The 'PATH' environment variable points to the JRE (Java Runtime
         Environment), rather than the JDK (Java Developer Kit).  The JDK already
         contains the JRE, so a separate JRE insallation  is not necessary.]
       [Fix: Set the 'PATH' environment variable to point to the JDK installation bi
    n
         directory.]
    2) 'JAVA_HOME' does not match the Java installation 'PATH' directory 'C:\Program
    Files\Java\jre6'.
       [Reason: The version of Java referenced in the executable 'PATH' environment
         variable does not match 'JAVA_HOME'.]
       [Fix: Make sure both the 'JAVA_HOME' and 'PATH' environment variables point t
    o the
         same installed JDK.]
    No warnings reported
    Further more these may help understand better
    C:\Dush\Workspaces\JavaWorkspace\OpenGTS>echo %JAVA_HOME%
    C:\Program Files\Java\jdk1.6.0_03
    C:\Dush\Workspaces\JavaWorkspace\OpenGTS>path
    PATH=C:\Program Files\PC Connectivity Solution\;C:\WINDOWS\system32;C:\WINDOWS;C
    :\WINDOWS\System32\Wbem;C:\Program Files\apache-ant-1.7.0\bin;C:\Program Files\J
    ava\jdk1.6.0_03\bin;C:\Program Files\MySQL\MySQL Server 5.0\bin;C:\Dush\Workspac
    es\JavaWorkspace\OpenGTS\bin;
    C:\Dush\Workspaces\JavaWorkspace\OpenGTS>The resolution suggests that the path point to the same instance of jdk installation but that has already been done,
    I do not understand from where does the
    C:\Program Files\Java\jre6 path get set.
    Please suggest..

    dushdushyant wrote:
    ** Found 2 Error(s)!
    1) The 'PATH' environment variable points to the JRE, rather than the JDK.
    [Reason: The 'PATH' environment variable points to the JRE (Java Runtime
    Environment), rather than the JDK (Java Developer Kit).  The JDK already
    contains the JRE, so a separate JRE insallation  is not necessary.]
    [Fix: Set the 'PATH' environment variable to point to the JDK installation bi
    n
    directory.]
    2) 'JAVA_HOME' does not match the Java installation 'PATH' directory 'C:\Program
    Files\Java\jre6'.
    [Reason: The version of Java referenced in the executable 'PATH' environment
    variable does not match 'JAVA_HOME'.]
    [Fix: Make sure both the 'JAVA_HOME' and 'PATH' environment variables point t
    o the
    same installed JDK.]
    No warnings reported
    C:\Dush\Workspaces\JavaWorkspace\OpenGTS>echo %JAVA_HOME%
    C:\Program Files\Java\jdk1.6.0_03
    C:\Dush\Workspaces\JavaWorkspace\OpenGTS>path
    PATH=C:\Program Files\PC Connectivity Solution\;C:\WINDOWS\system32;C:\WINDOWS;C
    :\WINDOWS\System32\Wbem;C:\Program Files\apache-ant-1.7.0\bin;C:\Program Files\J
    ava\jdk1.6.0_03\bin;C:\Program Files\MySQL\MySQL Server 5.0\bin;C:\Dush\Workspac
    es\JavaWorkspace\OpenGTS\bin;
    Put the java home bin folder on the path before %SYSTEMROOT%\system32
    set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_03
    set PATH=%JAVA_HOME%\bin;%PATH%

  • Passing importing parameter in  ABAP to  java script variable

    Hi Experts,
    I am calling a ABAP function module in javascript.Now how can I take importing parameter in  ABAP to java script variable. Because I need to give alert using the improting Paramter value...
    Thanks in advance..
    RR

    to pass ABAP variable value to javascript variable the syntax is
    var myjsvariable = "<%=abapvariable%>";
    Edited by: Durairaj Athavan Raja on Jul 29, 2009 2:39 PM

  • Convert legacy microsoft MBF double to java double

    Lo,
    i'm trying to read from old btrieve database some records, with double saved MBF format from microsoft.
    It seems it's mantissa, exponent and sign is completly different from IEEE double format, and dunno how to fix the problem, mostly don't know how to find exact structure of java double (how bits are used to design mantissa, sign, exponent).
    any idea?

    Already checked, it doesnt work.
    (It doenst take much to translate it to java from c.)
    It seems there's something strange about the mantissa, probably, or there is a mask over or the bytes and reversed, or only the gods, know what :o/

  • Retrieving parameter and assign it to double variable

    I have quick question.
    Can I retrieve parameter value and assign it to a previously
    defined double variable?
    For example, if there is a previously defined
    double variable named cost and a following tag
    <PARAM NAME=price VALUE=10.00>
    can I just do
    cost = getParameter("price");
    to retrive the value?
    Thanks

    Hi Kei,
    No you can't do
    cost = getParameter("price");because method "getParameter()" returns a "String" (not a 'double').
    But you can do something like this:
    String price = getParameter("price");
    double cost = Double.parseDouble(price);Note that the above is incomplete. The "parseDouble()" method may throw an exception. PLease check the relevant javadoc for more details.
    Hope this helps.
    Good Luck,
    Avi.

  • Java double

    hi reader
    am doing some exercises and wonder about calculations based upon java double. Is there any known issue regarding to faulty calculations utilizing double values ?? have attached my sample code..
    public abstract class Drink {
         String beschreibung = "Unbekanntes Getr�nk";
         int groesse = 0;
         int KLEIN      = 0;
         int NORMAL = 1;
         int GROSS      = 2;
         public String getBeschreibung(){
              return beschreibung;
         public int getGroesse(){
              return groesse;
         public void setGroesse(int groesse){
              this.groesse = groesse;
         public abstract double preis();
    public class Espresso extends Drink{
         public Espresso(){
              beschreibung = "Espresso";
         public double preis(){
              return 1.99;
    public abstract class TopicDecorator extends Drink{
         public abstract String getBeschreibung();
    public class Milk extends TopicDecorator{
         Drink getr�nk;
         int groesse = 0;
         public Milk(Drink getr�nk){
              this.getr�nk = getr�nk;
         public String getBeschreibung(){
              return getr�nk.getBeschreibung() + ", Milch";
         public int getGroesse(){
              this.groesse = getr�nk.getGroesse();
              return this.groesse;
         public double preis(){
              double preis = getr�nk.preis();
              if(getGroesse() == getr�nk.KLEIN){
                   preis += 0.15;               
              else if (getGroesse() == getr�nk.NORMAL) {
                   preis += 0.20;
              else if (getGroesse() == getr�nk.GROSS) {
                   preis += 0.25;
              return preis;     
    }whenever i test the application, the result of calculated price is not correct.

    result returned should look like 2.xx �
    but result is 2.xxxxxxxxx �
    test app:
    public class TestFrame {
         public static void main(String[] args) {
              Drink drink1 = new Espresso();
              System.out.println(drink1.getBeschreibung() + " " + drink1.preis() + " �");
              Drink drink2 = new HouseLabel();
              drink2.setGroesse(drink2.GROSS);
              drink2 = new Chocolate(drink2);
              drink2 = new Chocolate(drink2);
              drink2 = new Milk(drink2);
              System.out.println(drink2.getBeschreibung() + " " + drink2.preis() + " �");
    Message was edited by:
    digit-x

  • How to assign java script variable to a hidden parameter in JSP?

    Hi All,
    I want to assign the variable in the Jscript to a hidden parameter in JSP page.
    <select name="sortingOption" class="sortingOptions" onchange="changeSortOption(this)">
    <c:forEach var="sortingOption" items="${sortingOptionList}">
    <c:set var="sortingOptionValue" value="${sortingOption}" target="java.lang.String"/>
    <c:choose>
    <c:when test="${sortingOptionValue == sortingOptionValueFromRequest}">
    <option value="${sortingOptionValue}" selected="selected">${sortingOptionValue}</option>
    <input type="hidden" name="srchType" value="none"/>
    </c:when>
    <c:otherwise>
    <option value="${sortingOptionValue}">${sortingOptionValue}</option>
    </c:otherwise>
    </c:choose>
    </c:forEach>
    </select>
    In changeSortOption script,they capture the value selected by the user and then they submit the form.I want to assign that value to a hidden parameter in JSP,can someone tell me how to do that?
    I dont have the Jscript code with me right now to post here.

    To the point: just by accessing/manipulating the HTML DOM using JS. Learn JS and HTML DOM. There are basic tutorials at w3schools.com. Besides, your code syntax is still invalid. The input hidden elemend doesn't belong in a select element. Learn HTML. There's a basic tutorial at w3schools.com as well.
    For future HTML/JS problems please consult the appropriate forums. This has not much to do with JSP. There are ones at webdeveloper.com.

  • Passing struts-tag value to java / javascript variable in JSP

    Hello all,
    Im trying to pass the value got from the struts-tag to the java variable in the Jsp. However Im not able to get the o/p. Can u guys help me on this pls...
    <logic:notEmpty name="TreeBean" property="list">
        <logic:iterate id="Type" name="TreeBean" property="list" indexId="i">
         <br/><bean:write name="Type" />
        </logic:iterate>
    </logic:notEmpty>Here the list can be populated in the jsp page. However i want the values into jsp list. Im not able to populate the same..
    <% List jspList = null;
    %> I want the values into the jspList variable for further processing. Can u guz pls help me on this....

    Which do you want it in?
    A java variable for use in <% scriptlet code %> or a javascript variable for use on the client end?
    scriptlet:
    <jsp:useBean id="TreeBean" type="java.util.List" class="java.util.ArrayList" scope="?????" />
    Having scriptlet code on the page is considered bad coding style.
    What is it you are trying to accomplish by making the value accessible?
    What are you trying to do in java / javascript that can't be done with JSP tags?

  • Use a Java Script variable's value in some other  jsp ....how?

    Please help me.................
    <%@ page import="java.util.*" %>
    <%@ page language = "java" import="java.sql.*,javax.servlet.*,javax.servlet.http.*,java.util.*" session = "true" %>
    <HTML>
    <HEAD>
    <TITLE>Create Employee</TITLE>
    </HEAD>
    <BODY>
    <%
         Connection conn = null;
         Statement stmt = null;
         ResultSet rs = null;
         try {
              Class.forName("com.mysql.jdbc.Driver");
    conn = DriverManager.getConnection("jdbc:mysql://10.203.143.55:3306/bdaymgr" ,"root","mysql");
              stmt = conn.createStatement();
              rs = stmt.executeQuery("Select emp_id,emp_name From employee_info ");
              System.out.println("rs " + rs);
    %>
    <script language="JavaScript">
         function OnSubmitForm(){
         var box = document.form2.UserList;
         var where_to = box.options[box.options.selectedIndex].value;
         if(where_to =="")
    {document.write("Please select something");}
         else {Dont know what to do here }
         </script>
    </script>
    <center>
    <FORM NAME = "form2" onSubmit="OnSubmitForm();">
    <table>
    <TR>
         <TD width="11%">User ID : </TD>
         <TD width="180%"><select name="UserList" size="1">
         <option>-- Select A User ID --<option>
         <% while (rs.next()) {
         %>
         <option value='<%= rs.getString("EMP_ID")%>' ><%=rs.getString("EMP_ID") %></option>
         <% } %>
         </select>
         <input type="hidden" name="score" value="">
         <INPUT TYPE="SUBMIT" name="Submit" VALUE="Submit">
         </TD></TR>
    </TABLE>
    </FORM>
    </Center>
    <%
              stmt.close();
                   rs.close();
              catch(Exception e){
                   System.out.println("Error : "+ e);
                   response.sendRedirect("errorcreateSession.jsp");
    %>
    </BODY>
    </HTML>
    As u can see i have extracted emp_id from the employee_info table and populated it in my drop down list
    In the javascript i have used a variable "where_to" which keeps track of what the user has selected in the drop down list
    I want to use this value of "where_to" in some other other jsp(say Admin.jsp) to carry out an insert query
    how can i retrieve this value of "where_to" from Admin.jsp so that i can carry out my insert query
    Thanx in advance i certainly hope that u will help me

    I made these changes in my Guest.jsp page(as u mentioned):
    <FORM NAME = "form2" onSubmit="return OnSubmitForm();" action="Admin.jsp">
    <select name="UserList" size="1">
         <option>-- Select A User ID --<option>
    </select>
         <INPUT TYPE="SUBMIT" name="Submit" VALUE="Submit">
    <script language="JavaScript">
         function OnSubmitForm(){
         var box = document.form2.UserList;
         var where_to = box.options[box.options.selectedIndex].value;
         if(where_to =="")
    document.write("Please select something");
    return false;
    else
    return true;
    </script>
    Now have a look at my Admin.jsp page:
    <%@ page import="java.util.*" %>
    <%@ page language = "java" import="java.sql.*,javax.servlet.*,javax.servlet.http.*,java.util.*" session = "true" %>
    <HTML>
    <HEAD>
    <TITLE>Create Employee</TITLE>
    </HEAD>
    <BODY>
    <%
         Connection conn = null;
         Statement stmt = null;
         ResultSet rs = null;
         PreparedStatement ps = null;
         try {
              Class.forName("com.mysql.jdbc.Driver");
    conn = DriverManager.getConnection("jdbc:mysql://10.203.143.55:3306/bdaymgr" ,"root","mysql");
              String s=request.getParameter("UserList");
              String m=request.getParameter("month");
              String y=request.getParameter("year");
              String a=request.getParameter("amount");
              String sql="insert into contribution_info values(?,?,?,?)";
              ps=conn.prepareStatement(sql);
              ps.setString(1,s);
              ps.setString(2,m);
              ps.setString(3,y);
              ps.setString(4,a);
              ps.executeUpdate();
              System.out.print("Values Entered");
              %>
    <center>
    <FORM NAME = "form3" action="canBeAnyPage.jsp">
    Month :<br><input type=\"text\" name="month"><br>
    Year :<br><input type=\"text\" name="year"><br>
    Amount Paid :<br><input type=\"text\" name="amount"><br>
    <INPUT TYPE="SUBMIT" name="Submit" VALUE="Submit">
    </FORM>
    </center>
    <% stmt.close();
                   rs.close();
              catch(SQLException e){
                   System.out.println("Error : "+ e);
                   //response.sendRedirect("errorcreateSession.jsp");
    %>
    </BODY>
    </HTML>
    I dont know why but when i select one of the emp_id from the drop down list and press submit it does not show anything
    I can see the value of "UserList" in the url which is correct
    Probably there is some problem in my Admin.jsp page
    Please find time to have a look at my code
    Help would be really appreciated
    thanx

  • Java Double summation is not working properly

    public class Test {
         public static void main(String[] args) {
              double d = 0.6+4.6;
              System.out.println(d);
              /*float d2 = (float)(0.6d+4.6f);
              System.out.println(d2*1.0f);*/
    This is printing 5.199999999999999.
    I am using Java 1.6. Please suggest me how to do these type of double operations.

    >
    If d was as defined in the original post you don't get the expected result
    >
    That statement is not quite correct. Of course you get the expected result.
    Perhaps you meant to say 'you don't get the OP's expected result'?
    And I did read it all before I answered but it seems you misread Kayaman's response.
    Kayaman said
    >
    . . .you can't just do
    if(d == 5.2)
    with floating point numbers.
    >
    and, as I showed, that is clearly incorrect. You not only can do that but that is how you would check for equality with a particular value.
    The OP concluded
    >
    if the program is like this, false is printing. But the answer should be true.
    >
    I think we all agree that the OP is wrong that the answer should be true.
    But he is not wrong because you can't do 'd == 5.2' with floating point numbers.
    OP is wrong because comparing two numbers like 'd' and '5.2' that have any significant digits that differ will not result in equality.
    And neither Kayman nor you gave the OP that real reason why the code took a different branch than what the OP expected.
    My statement
    >
    The OP used 5.199999999999999 and that isn't equal to 5.2 so you take the FALSE branch.
    >
    is EXACTLY the explanation for why the OP's assumtion is wrong.
    The reason has nothing to do with the Java syntax.

  • Java static variables in Stored Java

    I'm wondering if someone in Oracle could relate their thinking with regards to static variables in stored java and why were these implemented as they were. The aspect I'm referring to specifically is how these are basically working as PLSQL package variables, i.e. with state maintained for the life of the session.
    Outside the database, in the "normal" Java world, statics will only live as long as the program is running. But in the Oracle DB world, the static continues to live as long as the session. With this in mind, doesn't this difference compromise the idea of just inserting working Java code into the Database? i.e. static variables now have to be initialized every time a method is called, and cannot be assumed to have default values. Does that not seem like a rather large departure from what a non-DB java programmer would be doing?
    Thanks in advance for your thoughts on this.
    Joe Tseng

    It should generally be the case that all calls in a session see the same static variable values. Some actions will terminate the java session (and lose the static variable state) without ending the RDBMS session, such as calling System.exit from java, but normally this can't happen within a single RDBMS call. Perhaps if you give more details on how you are making the call from java to PLSQL one could say more. In particular, if the call happens to be via the JDBC thin driver then the session running in the JDBC connection will be distinct from the calling session.

  • Shared java static variables

    I have an application where I would like to
    read from some small configuration tables
    and cache them into java variables, in order to avoid each stored procedure call to redo
    those queries. The configuration data is
    pretty static, so I don't worry about refresh
    problems.
    My first attempt to do that was using static
    final variables (like Vector). In our oracle
    environment however (8.1.7) each session
    seems to have its own copy of static final
    variables, resulting in each session to
    perform those queries for initializing all
    over again.
    firstly, i would like to find out if there is another way to share this data among java
    sessions, but otherwise I am curious how
    I can get the claims made in http://technet.oracle.com/products/oracle8i/pdf/8ir2java.pdf , page 6 to work.
    Specifically, here is what the document says:
    "In Oracel8i Release 2, JServer introduces the concept of "hotloaded" classes. Various core classes that
    initialize static variables known to be constant are pre-initialized during database creation time. When you use
    one of these classes in your program, the class loader loads the pre-initialized form. In many cases, the time
    required to initialize the static variables is itself quite significant, and now with the introduction of hotloaded
    classes that time is completely eliminated. In addition, the objects in these particular static variables are shared
    among all sessions. Hotloaded classes therefore improve performance by eliminating class initialization and
    they reduce per-user-session footprint by increasing the amount of data shared between sessions. Hotloaded
    classes provide improved performance and scalability "for free", with no user intervention. "
    the kind of initialization I have been
    trying is like:
    public static final int inti = func();
    this also didn't seem to work:
    public static final int inti;
    static {
    inti = ....;
    thanks,
    null

    I have an application where I would like to
    read from some small configuration tables
    and cache them into java variables, in order to avoid each stored procedure call to redo
    those queries. The configuration data is
    pretty static, so I don't worry about refresh
    problems.
    My first attempt to do that was using static
    final variables (like Vector). In our oracle
    environment however (8.1.7) each session
    seems to have its own copy of static final
    variables, resulting in each session to
    perform those queries for initializing all
    over again.
    firstly, i would like to find out if there is another way to share this data among java
    sessions, but otherwise I am curious how
    I can get the claims made in http://technet.oracle.com/products/oracle8i/pdf/8ir2java.pdf , page 6 to work.
    Specifically, here is what the document says:
    "In Oracel8i Release 2, JServer introduces the concept of "hotloaded" classes. Various core classes that
    initialize static variables known to be constant are pre-initialized during database creation time. When you use
    one of these classes in your program, the class loader loads the pre-initialized form. In many cases, the time
    required to initialize the static variables is itself quite significant, and now with the introduction of hotloaded
    classes that time is completely eliminated. In addition, the objects in these particular static variables are shared
    among all sessions. Hotloaded classes therefore improve performance by eliminating class initialization and
    they reduce per-user-session footprint by increasing the amount of data shared between sessions. Hotloaded
    classes provide improved performance and scalability "for free", with no user intervention. "
    the kind of initialization I have been
    trying is like:
    public static final int inti = func();
    this also didn't seem to work:
    public static final int inti;
    static {
    inti = ....;
    thanks,
    null

Maybe you are looking for

  • How to compute a global SCORE over a few oracle text indexed tables?

    Dear experts! I want to search a website with Oracle Text. The website consists of four tables: - site - chapter - text - binaries Each table has two or three columns which should be indexed with oracle text. So I have created a MULTI_COLUMN_DATASTOR

  • Having a problem updating my i-phone. I keep getting error 6

    My I phone will not download the new software. I keep getting error 6 not complete.

  • Connecting to LDAP using JNDI

    I am trying to connect to LDAP to check an entry. Following is the servlet code I am using. /* @author This class is establish to connect the LDAP user directory and get the user attributes (SSO_USERID, USER_ID, USER_NAME and USER_MAIL) from the LDAP

  • Keep getting error (-9812) message in itunes

    Hello, I really hope someone can help me. I am currently unable to sign into itunes as each time I try I get the message - We could not complete your itunes store request. An unknown error has occurred - I have never had any problems before however s

  • Modify PO from external system

    Hi all, We are implementing SRM 5.0 with extended classi scenario. Until now we have a R3 system where we create PO, but we also have got a functionality for modifing particular information of PO in a lagacy system, that comunicate with R3 between id