ffcrg / ecpiww

A wireless EnergyCam Setup with a Raspberry Pi to monitor the energy usage
34 stars 18 forks source link

Decimals truncated of Logged Values #4

Open dbedrenko opened 9 years ago

dbedrenko commented 9 years ago

In ecpiww.c in Log2File() on line:

sprintf(param, "./add2vz.sh %d %ld ", meterindex+1, (long int)metervalue*1000);

It typecasts metervalue before the scaling is done. A value of 140.1 is typecast to long int 140, and only then scaled to become 140000. but it should be 140100.

Fix this by scaling first then typecasting:

sprintf(param, "./add2vz.sh %d %ld ", meterindex+1, (long int)(metervalue*1000));