Article View: aus.computers.java
Article #334Re: Converting a double to an integer
From: Daniel Baldoni
Date: Sun, 22 Oct 2000 00:00
Date: Sun, 22 Oct 2000 00:00
43 lines
2440 bytes
2440 bytes
G'day Livio, Livio Colbertaldo <libo@ozemail.com.au> wrote: >i have a variable A which is a type double and i need it converted to an >integer >and i cant work out how to use the intValue class in double >could some1 please help or is there another way of doing it? Assuming your variables are actually objects, and you mean they're, respectively, a Double and an Integer, the following code segment should highlight what you need to do... Double d = new Double(<some value>); Integer i = new Integer(d.intValue()); The point here is that Double.intValue() returns an int base type, not an Integer object. If, however, your two variables are actually base types (int and double), this should show you what you need... double d = <some value>; int i = (int) d; You can simply cast when they're base types. Remember though that you lose precision moving from double to int. You should be able to determine from the above two cases what to do if you have one base type and one object. Good luck. -------------------------------------------------------+--------------------- Daniel Baldoni BAppSc, PGradDipCompSci | Technical Director require 'std/disclaimer.pl' | LcdS Pty. Ltd. -------------------------------------------------------+ 856B Canning Hwy Phone/FAX: +61-8-9364-8171 | Applecross Mobile: 041-888-9794 | WA 6153 URL: http://www.lcds.com.au/ | Australia -------------------------------------------------------+--------------------- "Any time there's something so ridiculous that no rational systems programmer would even consider trying it, they send for me."; paraphrased from "King Of The Murgos" by David Eddings. (I'm not good, just crazy)
Technical Details
Message-ID:
<39f32f32$0$18995@motown.iinet.net.au>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3qRH5.1952$SF5.40850@ozemail.com.au>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d6db,722a5f81b691deb5
X-Google-Attributes: gid10d6db,public
From: Daniel Baldoni <dbaldoni@iinet.net.au>
Subject: Re: Converting a double to an integer
Date: 2000/10/22
Message-ID: <39f32f32$0$18995@motown.iinet.net.au>
X-Deja-AN: 684509608
Distribution: world
References: <3qRH5.1952$SF5.40850@ozemail.com.au>
X-Trace: news.iinet.net.au 972238642 18995 xppg54@203.59.83.243
Organization: LcdS Pty. Ltd.
User-Agent: tin/1.4.2-20000205 ("Possession") (UNIX) (Linux/2.2.13-22mdk (i686))
Newsgroups: aus.computers.java