@Joe101
Yes... But each time you some one uses the program, The decimal will change then it won't know what to do, as far as rounding up or rounding down so if i make a function prototype of it and use either ceil() or floor() chances are it will be wrong most of the time...
So any suggestions of an alternate way...
anybody?
If you are trying to truncate, that should work fine. It will multiply it up to 100, taking all the values you want as an integer part, with the left over stuff you want off in decimals. It will then divide it by 100. I don't know how casting gets into it but it should work exactly as you planned it. Have you even tried it or are you discrediting it based on mathematical evidence that 100/100=1?
@tummychow
I Have no idea what you are trying to say...
For example I think you said something recently about how British education is the worst, and you learn mostly on your own. (or was it not you who said that)
I'm asking, have you tried it?
And no, that wasn't my line.
Think of it this way. You multiply 3.1415926 by 100. (You might have to cast it to int first, I am not sure how the compiler will respond). You end up with 314.15926. Cast it to int and you get 314. Divide by 100 and you get 3.14 - the truncation of 3.1415926, to two decimal places.
Casting is converting from one type to another. That's why it works. When you convert to integer, the extra places are automatically truncated off because the type has no room for them. So you multiply the DOUBLE by 100, cast the result to INT, then get a DOUBLE of the int, divided by 100.
And I meant, try it as in create it in actual code, compile and run it. Not just type it out and look at it from a new perspective.
@tummychow
okay so an int to a double vice versa.
but then the program will compile successfully except for the fact it will display a warning.
I was taught to treat compiler warnings like compiler errors.
And yes, I did create it in actual code. It is above 3 posts. But it is wrong. So I will revise it in the morning and then post if i got it wrong.
Please respond about the compiler warnings.
Sorry for the trouble of you explaining it to me about 4 times. I have been half asleep all day.
You can ignore most compiler type conversion warnings. Warnings are just that - warnings, not errors. In essence, they inform you that the type conversion entails a loss of data or accuracy... which is exactly what you want when truncating a floating-point value.