Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Reading floats from a notecard

Burntout Homewood
Registered User
Join date: 20 Jul 2007
Posts: 4
09-29-2007 17:38
I have a settings notecard that uses some floats. It seems like when I try to convert the values from string to float I lose everything after the decimal place. anyone have a good way to convert a string to a float? I'm thinking about converting each digit to an integer and multiplying it by 10 or 100, 1000 etc and adding them together and then assign it to a float / 10000.

For what I need 4 decimal places would be plenty but is there a better way?
Also these settings will always be a positive number.

Thanks :-)
Trevor Langdon
Second Life Resident
Join date: 20 Oct 2004
Posts: 149
09-29-2007 18:44
Burntout--

Seems like you should be able to type-cast your string as a float all at once after extracting the float portion from the notecard line:

float fMyFloat = (float)your-notecard-string
Burntout Homewood
Registered User
Join date: 20 Jul 2007
Posts: 4
09-29-2007 18:55
From: Trevor Langdon
Burntout--

Seems like you should be able to type-cast your string as a float all at once after extracting the float portion from the notecard line:

float fMyFloat = (float)your-notecard-string

yeah thats what I did. The string part had "1.9999" which was changed to 1.. seems like it always rounds down.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
09-29-2007 19:02
(Oooops. I see you already have it figured out)

CODE


default
{
touch_start(integer total_number)
{
float a = 1.2345678;
string b = (string)a;
float c = (float)b;
llOwnerSay((string)c);
}
}

outputs: 1.2345678
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Burntout Homewood
Registered User
Join date: 20 Jul 2007
Posts: 4
09-29-2007 19:58
hmm, well if you guys are so convinced that it should work that way I guess I need to look at my notecard reading code closer to make sure I'm not cutting off the decimals
Flennan Roffo
Scripter
Join date: 29 Sep 2007
Posts: 26
09-30-2007 13:22
From: Burntout Homewood
hmm, well if you guys are so convinced that it should work that way I guess I need to look at my notecard reading code closer to make sure I'm not cutting off the decimals

Post your notecard here.
Are you sure you did not accidentaly use comma instead of dot?
_____________________
Logic Scripted Products and Script Services
Peacock Park (187,228,69)

*** Get your free copy of SL Mail today! ***
Monica Balut
Beam-Me
Join date: 18 Feb 2007
Posts: 311
09-30-2007 13:31
Remember too that floats are not always exact. So it's not unlikely that some numbers will be off by a tiny fraction from what you read in. That's why you never do exact comparisons of floats but check that a number is within a tiny range of the target.
Burntout Homewood
Registered User
Join date: 20 Jul 2007
Posts: 4
09-30-2007 15:52
lol ok, I'm a moron.

I had a bunch of settings in this notecard and I guess on this one I had it set to integer. I changed it to float and it worked perfect, imagine that. :-)

Sorry for wasting your time.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
09-30-2007 17:46
From: Burntout Homewood
lol ok, I'm a moron.

I had a bunch of settings in this notecard and I guess on this one I had it set to integer. I changed it to float and it worked perfect, imagine that. :-)

Sorry for wasting your time.


Well I don't know about you but I seem to learn more from my dumb mistakes then from my regular ones :)
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Trevor Langdon
Second Life Resident
Join date: 20 Oct 2004
Posts: 149
09-30-2007 23:15
Burntout--
Glad to hear you have it working!

From: Jesse Barnett
Well I don't know about you but I seem to learn more from my dumb mistakes then from my regular ones :)


I'm with you 100% on this one Jesse :)