🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: aus.computers.java
2 messages
2 total messages Started by Livio Colbertaldo Fri, 20 Oct 2000 00:00
Converting a double to an integer
#326
Author: Livio Colbertaldo
Date: Fri, 20 Oct 2000 00:00
4 lines
840 bytes
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?
Re: Converting a double to an integer
#334
Author: Daniel Baldoni
Date: Sun, 22 Oct 2000 00:00
43 lines
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)
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads