hi, I want to do some maths where use of floating numbers is unavoidable.
if for example i have to do 5 x 0.5 , i am aware i can multiply both sides by 10 to "get rid of the decimal place" and then divide by 100 after: so 50x5 = 25 / 100 =2.5 and i can store the integer "2" in a variable by using "/" and "//" to store the remainder "0.5" in another variable
but i wonder if there is a better way?
my problem is i want to calculate RMS watts and display on a LCD. The current is a peak current reading that can range from 0.2 Amps to 70 Amps and RMS Voltage is assumed as 240V
To calculate RMS Watts i need to multiple peak current by RMS volts and multiply by 0.707 (or divide by 1.414)
lets assume peak current is 5 Amps
I could multiply by 100 first (except 240V which can be 24) so it is: (24 x 500) X 707 then divide by 10,000 to give 848.4 W . The problem is that in a word variable you can only store 256x256=65536 before it rolls over to 00000, so the above maths would not work.
any better way of doing this sort of thing. I still want to keep the decimal place of the wattage so would need to do maths for the interger and maths for the remainder.
regards jon.
if for example i have to do 5 x 0.5 , i am aware i can multiply both sides by 10 to "get rid of the decimal place" and then divide by 100 after: so 50x5 = 25 / 100 =2.5 and i can store the integer "2" in a variable by using "/" and "//" to store the remainder "0.5" in another variable
but i wonder if there is a better way?
my problem is i want to calculate RMS watts and display on a LCD. The current is a peak current reading that can range from 0.2 Amps to 70 Amps and RMS Voltage is assumed as 240V
To calculate RMS Watts i need to multiple peak current by RMS volts and multiply by 0.707 (or divide by 1.414)
lets assume peak current is 5 Amps
I could multiply by 100 first (except 240V which can be 24) so it is: (24 x 500) X 707 then divide by 10,000 to give 848.4 W . The problem is that in a word variable you can only store 256x256=65536 before it rolls over to 00000, so the above maths would not work.
any better way of doing this sort of thing. I still want to keep the decimal place of the wattage so would need to do maths for the interger and maths for the remainder.
regards jon.