[Solved]simple math went wrong!!! help

I am building a battery discharger. I got shuntMa (current right), then trying to figure out shuntMah (mah) , first 1-9 mah seems to be fine, but when it go up to 10 mah, the number went to negative. anything wrong with my code? It take a reading of ma every second, then add it to the total, and then the total is divided by 3600 (60minX60hr) from maSec > mah.

also, I went into a problem where doing the ma as well. why I need to do math with float? it won't work like this shuntMa=shuntVal*(5/102310000.92); , but works like this shuntMa=shuntVal*(5.0/1023.01000.00.92);

unsigned long currentSec=millis();
if(currentSec-previousSec>1000) {
SEC++; 
previousSec=currentSec;
if(shuntMa>1){shuntMatotal=shuntMatotal+shuntMa;}
}
int shuntVal= analogRead(shuntPin);
shuntMa=shuntVal*(5.0/1023.0*1000.0*0.92);
shuntMah=shuntMatotal/3600;

Sounds like you're wrapping on an "int" (-32768 to +32767)
Post your code.

int shuntVal= analogRead(shuntPin);
shuntMa=shuntVal*(5.0/1023.0*1000.0*0.92);
shuntMah=shuntMatotal/3600;

So, shuntMa is defined as a signed int, then you do a whole load of floating point maths on it. Do you think that will work correctly ?

AWOL:
Sounds like you're wrapping on an "int" (-32768 to +32767)
Post your code.

yes, I did. why I didn't think of that. I have rewrote my code over and over again, just missed this tiny thing. thanks

UKHeliBob:

int shuntVal= analogRead(shuntPin);

shuntMa=shuntVal*(5.0/1023.01000.00.92);
shuntMah=shuntMatotal/3600;



So, shuntMa is defined as a signed int, then you do a whole load of floating point maths on it. Do you think that will work correctly ?

I need to print shuntMa to a LCD, float is not supported for LCD, so I have to use int. but still, it is confusing when do math with this int or float thing.

float is not supported for LCD

Is that right ?