0

I am running C++14 on MacOS High Sierra.

I have an uint16_t returned from a method and the value can range from 100 to like 8000 odd.

I want to convert it to a float. So, if it is 289 then the float should be 289.0. I am trying all different ways to cast the uint16_t but it my float variable always gets zeroes.

uint16_t i_value = 289;

Tried this:

float f_value = static_cast(i_value);

And tried this:

float f_value = (float)i_value;

But nothing works.

Question:
How can I cast uint16_t into a float?

auburg
  • 1,373
  • 2
  • 12
  • 22
TheWaterProgrammer
  • 7,055
  • 12
  • 70
  • 159

1 Answers1

2

It is an implicit conversion (both ways), no cast is required:

uint16_t i_value = 289;
float f = i_value;
Maxim Egorushkin
  • 131,725
  • 17
  • 180
  • 271