system
November 14, 2012, 3:48pm
1
Hi.
This is my test sketch:
void setup()
{
Serial.begin(9600);
float a = 1.23;
Serial.println(a);
float b = 5/255;
Serial.println(b);
}
void loop()
{
}
This is its output:
1.23
0.00
Can you please help me understand why it is printing 0.00 ? How can I print my float variable?
Thanks,
Dan
system
November 14, 2012, 3:59pm
2
It is printing the value of your float variable, the value of which is 0.00.
float b = 5.0/255.0;
or
float b = (float)5/(float)255;
(though one "float" would be sufficient)
system
November 14, 2012, 4:31pm
3
Thanks a lot, that worked!
How can I vote for your answer so to increase your karma?
system
November 14, 2012, 4:32pm
4
Click on the plus sign next to the Karma figure.
system
November 14, 2012, 4:33pm
5
I can't see it - probably I am too new to the forum for being able to vote
system
November 14, 2012, 4:39pm
6
I can't see it - probably I am too new to the forum for being able to vote
I voted for you.
Above AWOL's avatar, there is a karma listing. The little green thing is what you click to bump his karma (or dogma).
When your karma runs over somebody's dogma, it's nice to say you're sorry.
I've been here more than year and now I find out what those things on the forum mean. If I had known from the start then some-a-yuns would have a lot more.