Strange behavior for map()

I'm trying to map a range of numbers to a float, but I'm unable to get any resolution beyond whole numbers. In other words I'm getting (for example) 8.00 instead of 8.25.

Here's a stripped down sketch:

void setup() {
  // put your setup code here, to run once:

  Serial.begin(115200);

}

void loop() {

  delay(1000);

  //float lower_number=2.71;
  //float higher_number=4.88;
  //float current_number=3.12;

  float lower_number=1.0;
  float higher_number=100.0;
  
  float current_number=28.3;

  int NUM_LEDS=40;
  
  
  float led_height = map( (float)current_number*1000, (float)lower_number*1000, (float)higher_number*1000, 1.0, (float)NUM_LEDS);
  //float led_height = map( current_number, lower_number, higher_number, 1.0, (float)NUM_LEDS);

  Serial.println(led_height);

}

This yields 11.00.

Any idea why it's rounding to .00?

Should I be using different variable type than float?

Thanks for any help.

A quick look at the language documentation shows this:

"The map() function uses integer math so will not generate fractions, when the math might indicate that it should do so. Fractional remainders are truncated, and are not rounded or averaged.".

Paul

As Paul says...
Look at this:

Thanks for that.

For anyone else coming this way, from the docs for map():

As previously mentioned, the map() function uses integer math. So fractions might get suppressed due to this. For example, fractions like 3/2, 4/3, 5/4 will all be returned as 1 from the map() function, despite their different actual values. So if your project requires precise calculations (e.g. voltage accurate to 3 decimal places), please consider avoiding map() and implementing the calculations manually in your code yourself.

This workaround seems to work well:

  float lower_number=1;
  float higher_number=100;  
  float current_number=28;

  int NUM_LEDS=10;
  
  int led_height = map( current_number*100, lower_number*100, higher_number*100, 1*100, NUM_LEDS*100);  
  float led_height2 = led_height/100.0;

Note that I'm dividing by 100.0 (not 100), otherwise it doesn't reliably treat it as a float.

Let me know if anyone sees any possible issues with that, or a way to tidy it up.

Give it some time and create a float version for map()! Just aim right.

Why not use fmap?

In what library do I find that? Not in Arduino reference as I can se.