Dry_rubber_Chicken
2012-03-08 13:57:24 UTC
I have an example in my book using value such as
float carpet_cost = 7.35; //This IS a float and not a double, right?
I declare this as a float and get a warning about truncation from double.
If I put the
float 7.35f
I get no such warning, but results like a float.
I was under the impression that float would equal say
7.3500001
while a double would be
7.350000000000001.
Why would it even consider initializing that variable as a double(4byte) when I specifically told it to init a float(2byte). Again, this code without the trailing F, warns of a conversion from double to float with a decalred float. Also, if you're feeling generous, is there no Single in C++?
#include "stdafx.h"
using namespace System;
int main(array
{///Begin main code block
float ii_carpet_price_per_yard = 1.32f;
float ii_room_width = 12.21f;
float ii_room_length = 13.52f;
float ii_room_height = 9.63f;
const int ii_feet_per_yard = 3;
float ii_room_width_yards = ii_room_width / ii_feet_per_yard;
float ii_room_length_yards = ii_room_length / ii_feet_per_yard;
float ii_total_carpet_price = (ii_room_length_yards * ii_room_width_yards) * ii_carpet_price_per_yard;
Console::Write(" - {0} - {1} - {2} -" , ii_total_carpet_price, ii_room_length_yards, ii_room_width_yards);
Console::Read();
return 0; ///Kill it with fire
}///End main code block