Glitch or?
#1

Alright I attempted something but theres a problem.

PHP код:
#define PRICE 0.70
printf("%.2f",PRICE); 
it will output as 0.69. Only happens with 0.70
Reply
#2

Slightly odd, but not totally unexpected given the way floating point arithmetic works. They aren't very precise but good enough for most purposes. The number might as well have been stored as 0.699999... but because you cut it off at two characters it displays that.

https://www.youtube.com/watch?v=PZRI1IfStY0
Reply
#3

You could show the number as 2 integers separated by a point.

Код:
new
    Float: price = 0.70,
    
    before = floatround(price, floatround_tozero),
    after = floatround(price * 100) - before * 100;
	
printf("%i.%i", before, after);
Multiple it by 10^x with x being how many numbers there are after the decimal point.
Reply
#4

PHP код:
#define PRICE 0.70 
if(floatcmp(0.70PRICE) == 0)
    
printf("0.70");
else 
    
printf("%f",PRICE); 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)