Problems using System.println with a floar variable

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

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)

Thanks a lot, that worked!

How can I vote for your answer so to increase your karma?

Click on the plus sign next to the Karma figure.

I can't see it - probably I am too new to the forum for being able to vote :-(

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.