Kryston
Kryston

Reputation: 185

Simple int to float conversion in c++

My function so called "inverzMatrika" returns an int type of variable. I need to convert it to a floating-point number. Any suggestions?

float inverz;
inverz = (float)(inverzMatrika(matrika));

Upvotes: 1

Views: 8672

Answers (3)

cseav
cseav

Reputation: 107

You need not to worry about this conversion because it will be implicitly handled by the compiler. We don't lose data on conversion from int to float, hence no explicit type-casting tricks are required here.

Upvotes: -1

SOFKiNG
SOFKiNG

Reputation: 385

Try

 double inverz;
 inverz=  (double )(inverzMatrika(matrika));

Or

float inverz = static_cast<float>(inverzMatrika(matrika));

Upvotes: 0

billz
billz

Reputation: 45470

use static_cast, don't use C style cast

float inverz = static_cast<float>(inverzMatrika(matrika));

Upvotes: 2

Related Questions