problm with float value
-
HI, i want to convert my Answer to float from integer value as in my code follows float k =0.0; int count = 0; CString str; for (int i=30;i <= 1440; ) { k= i/60; /// here problem is //// if i = 90 then result should be 90/60 = 1.50 ////// its gives 1.00 ,, but its should be 1.50 //// in all case of any.50 it gives any.00 str.Format(_T("%d min. or (%2.02f Hrs)"), i , k); m_ctrl.InsertString(count++, str); i= i+30; } i hope u got the problm ,, that is i also need answer in shape of 1.00 , 1.50 , 2.00 , 2.50 etc. but its shows 1.50 , 2,50 ..as 1.00 , 2.00 respectvly. measn it round .50 to lower .00 value thanx
-
HI, i want to convert my Answer to float from integer value as in my code follows float k =0.0; int count = 0; CString str; for (int i=30;i <= 1440; ) { k= i/60; /// here problem is //// if i = 90 then result should be 90/60 = 1.50 ////// its gives 1.00 ,, but its should be 1.50 //// in all case of any.50 it gives any.00 str.Format(_T("%d min. or (%2.02f Hrs)"), i , k); m_ctrl.InsertString(count++, str); i= i+30; } i hope u got the problm ,, that is i also need answer in shape of 1.00 , 1.50 , 2.00 , 2.50 etc. but its shows 1.50 , 2,50 ..as 1.00 , 2.00 respectvly. measn it round .50 to lower .00 value thanx
Hi ! Instead of using
k= i/60;
usek= i/60.00;
When both operand of a division are integer, the result will be automatically an integer (even if this is not a round number). When one operand is float, the result will be a float also. -
Hi ! Instead of using
k= i/60;
usek= i/60.00;
When both operand of a division are integer, the result will be automatically an integer (even if this is not a round number). When one operand is float, the result will be a float also.thanks .. it works..