Closed Thread Icon

Preserved Topic: a little hint on JAVA plz (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=16361" title="Pages that link to Preserved Topic: a little hint on JAVA plz (Page 1 of 1)" rel="nofollow" >Preserved Topic: a little hint on JAVA plz <span class="small">(Page 1 of 1)</span>\

 
galaxal
Paranoid (IV) Inmate

From:
Insane since: Oct 2000

posted posted 12-05-2001 22:19

Hey:

if I have
float n = 12.34;
how can I get the length of the variable? For instance, in this case it's obviously 5 characters including the decimal point. But if n is unknown, how can I know how many characters there is in it?
(I tried n.toString(), but compiler said it can't be dereferenced)

thanx alot.

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 12-05-2001 22:27

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 12-06-2001 01:15

are you sure you can cast a float on string? (inconvertible types)
im no java-expert, but i doubt this is possible.
*waits to be corrected *

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 12-06-2001 02:00

It's been a while since I did any reading in my Java book, but I think you should a least be able to (as InI suggests) cast the float to a string, and then check it's size.

And like Grumble...

I also wait to be corrected

-Butcher-

RoyW
Bipolar (III) Inmate

From:
Insane since: Aug 2001

posted posted 12-06-2001 03:31

You can use the static method "toString" of the "Float" class.

Float.toString(n).length();

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 12-06-2001 07:08

Notice you are not type casting such as

String x = (String)float;

you are type casting by adding the float to a string.

String x = "" + float + "";

This is the same as any other form of creating a string with variables added. Just notice you are casting it by adding two null values to either side.

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 12-06-2001 08:25

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

galaxal
Paranoid (IV) Inmate

From:
Insane since: Oct 2000

posted posted 12-07-2001 01:31

thank you very much Ini, and everybody else that intended to help.

I like s = "" + n + "";

man, I used that trick quite alot when I was playing with javascript.
and damn me, all those upcasting and downcasting and exceptions really reeally got my brain out.

sincerely, I appreciately all you help !!


« BackwardsOnwards »

Show Forum Drop Down Menu