PDA

View Full Version : How to initialize a Float?



pointer
04-17-2008, 02:38 PM
hi, i wan't to 'pre-set' a Float, but it always says incompitable types
how do i pre-set a Float?

Yakman
04-17-2008, 05:51 PM
EvilChicken!
this is the java programming section, he probably isnt talking about scar

in java, decimal numbers are normally treated as doubles, you can make them floats by adding the letter 'F' after it



float hello = 5.34F;


theres a class Color with constructor Color(float red, float green, float blue)
you would use it like this



Color c = new Color(0.5F, 0.5F, 1F);

senrath
04-17-2008, 05:54 PM
I don't quite usderstand whay you're doing.
If you want to set a constant float, then:
const
VersionNumber = 0.23

If you want to pre-set a variable float, then
var
VersionNumber: extended;

begin
VersionNumber := 0.2;
WriteLn(FloatToStr(VersionNumber));
end.


I haven't tested it, but it should work.

That is Pascal syntax, not Java.
IIRC, this is what you need to do:

public float name = (number you want here)F; //for a variable

public static final name = (number you want here)F; //for a constant

HOWEVER, I would recommend using the type double instead of float. I don't remember exactly why at the moment, but it does mostly the same job but better.

EvilChicken!
04-17-2008, 07:01 PM
Owmygod.
I'm so sorry. Gah. >_<

*hides in corner*
*gets back from corner*
*deletes first post*
*goes back to corner*

pointer
04-18-2008, 08:37 PM
ty, my calculator is now fully complete