var has a range of about -999999.999..+999999.999 which is not suitable for your calculations. You should make your calculations using double typed variables and use str_printf to convert them to displayable strings.