Reputation: 37
I couldn't find a match to what I wanna ask. Why cant I display tan (39/180*3.142)
?
Instead it gives me 0.0000
, I need the decimals.
void __fastcall TForm1::Button1Click(TObject *Sender)
{
float h, a, d;
char* number = new char[255];
a = tan (39/180*3.142);
sprintf(number, "%.6f", a);
Height->Text = number;
}
Please advice. Thnx.
Upvotes: 1
Views: 1295
Reputation: 70001
You are dividing two integers, they will give you zero if the result will be 0.something. So you need to cast one into a float.
(39 / (float)180 * 3.142);
Or use float numbers
(39.0f / 180.0f * 3.142);
Upvotes: 2
Reputation: 49261
try using float numbers, it might calculate 39/180 (integers) as 0:
a = tan (39f/180f *3.142);
Upvotes: 3