문제

I have basic doubt.I have to convert float minutes =( (10.09/60 ) % 60); but error is invalid to binary expression(double to double). how can I make this calculation easy.. What I am trying is firstly float minutes =( (10.09/60 ) then trying to convert minutes into NSInterger to solve module (%) operation..

but how can I do this...or else suggest other solution to get this calculation..

float minutes =( (10.09/60 ) % 60);

도움이 되었습니까?

해결책

The % operator doesn't work on floating-point values. You'll have to use a function to calculate what you want. Here's the basic pseudocode of what it would look like:

B % A = B - (floor(B / A) * A)

There are also library functions which will do this for you in math.h or tgmath.h

Also, you can use: fmod() or fmodf() from .

다른 팁

To use %, you have to use an int. So : (int)(10.09)%60 should work.

You can use following operations depends upon requirement

float myFloat = 3.333

 //for nearest small integer:
int result = (int)ceilf(myFloat );

 //for nearest big integer:
int result = (int)roundf(myFloat );

 //for nearest integer:
int result = (int)floor(myFloat);

//For just an integer value int result = (int) (myFloat);

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top