Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Divide two integers and get a float
Message
Information générale
Forum:
Borland C++ Builder
Catégorie:
Librairie C++ standard
Titre:
Divide two integers and get a float
Divers
Thread ID:
01003810
Message ID:
01003810
Vues:
80
Consider the following code:
char szRes[25];
int iOne = 7;
int iTwo = 6;
float fRes = iOne / iTwo;
sprintf(szRes, "%.3f", fRes);
Application->MessageBoxA(szRes, "Result",0);
When I run this code I get a messagebox with the number 1.000. I would like to see the result being 1.167. I underdstand why I get the result I am getting (integer division), but how can I get the result I want (read: the "correct" result)?

Einar
Semper ubi sub ubi.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform