[solved]Tiny bug that I can't see is terrific: math is not correct

Almost got everything right, then when increasing my pwm, the output value go negative. normally, when It goes negative, and the math is correct, it is because value overflow, but I don’t think so here. realMa is not a huge number. then it must be the math. can anyone find this tiny bug for me plz? thank you

here is my serial output:

shunt:1049
-------------
pwm:180
-------------
Pwm:30
-------------
realMa:314
-------------
shuntTotal:9121
------------------------------------


shunt:1044
-------------
pwm:155
-------------
Pwm:40
-------------
realMa:-237
-------------
shuntTotal:8884
------------------------------------


shunt:0
-------------
pwm:155
-------------
Pwm:40
-------------
realMa:-235
-------------
shuntTotal:8649
------------------------------------

and here is my sketch:

#include <Wire.h> 
#include "ClickButton.h"
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address/ pins


ClickButton ba(9, LOW, CLICKBTN_PULLUP);
ClickButton bb(8, LOW, CLICKBTN_PULLUP);

int sec=0;
int Min=0;
int Switch=1;
int pwm=255;
int Pwm=0;
int shunt=0;
int mah=0;

int realMa=0;

unsigned long shuntTotal=0;
unsigned long nowtimer=0;
unsigned long pretimer=0;

unsigned long nptimer=0;
unsigned long pptimer=0;
//=====================================================================================

void setup()
{  
  Serial.begin(9600);
  lcd.begin(16,2);               // initialize the lcd   
  ba.multiclickTime = 50;
  bb.multiclickTime = 50;    

}

//=====================
void loop()
{
  ba.Update();
  bb.Update();  

  pwm=constrain(pwm, 0, 255);  // limited pwm from 0 to 255
  Pwm=map(pwm, 0,255, 100,0); // map pwm to Pwm for percentage reading. it's connected to PNP transisotr, so 255=0;

  nowtimer=millis();
  if(nowtimer-pretimer>=1000) {
    sec++;
    shuntTotal+=realMa;

    Serial.print("shunt:");
    Serial.println(shunt);
    Serial.println("-------------");    
    
    Serial.print("pwm:");
    Serial.println(pwm);      
    Serial.println("-------------");
    
    Serial.print("Pwm:");
    Serial.println(Pwm);  
    Serial.println("-------------");
    
    Serial.print("realMa:");
    Serial.println(realMa);  
    Serial.println("-------------");
    
     Serial.print("shuntTotal:");
    Serial.println(shuntTotal);
    Serial.println("------------------------------------");    
       

    pretimer=nowtimer;    
  }

  if(sec==60){
    Min++; 
    sec=0;
  }

  char linea[17];
  sprintf(linea, "%01dCC-MarkII %02d:%02d", Switch, Min, sec);
  lcd.setCursor (0,0); 
  lcd.print (linea);   
  nptimer=millis();


  if(nptimer-pptimer>=200) {
    char lineb[17];
    sprintf(lineb, "%03d %04dma %04dC", Pwm, realMa, mah);
    lcd.setCursor (0,1); 
    lcd.print (lineb);
    
    pptimer=nptimer;
  }



  //================================  

  int shuntVolt= analogRead(A0);   // read the shunt resistor voltage
  shunt = shuntVolt*5.0/1024.0*1000.0; // do the math to get shunt current 

  if(shunt>10){                         // if shunt current is more than 10ma
    realMa=shunt*Pwm/100.0;             // realma equals to (the reading * Pwm duty cycle )
  }

  mah=shuntTotal/3600;     

  if(Switch==1) analogWrite(3, pwm);
  else analogWrite(3, 255);


  if(ba.clicks==1) pwm-=25;
  if(bb.clicks==1) pwm+=25;  

  if(ba.clicks==-1) Switch=!Switch;
  if(bb.clicks==-1) ;

}

realMa=shuntPwm/100.0;
realMa=(1044
40)/100.0;
realMa=(41760)/100.0;

Oops. Just exceeded 32767.

Maybe this help:

Programming Tips:

Know that integer constants default to int, so some constant calculations may overflow (e.g. 60 * 1000 will yield a negative result).
Choose variable sizes that are large enough to hold the largest results from your calculations
Know at what point your variable will “roll over” and also what happens in the other direction e.g. (0 - 1) OR (0 - - 32768)
For math that requires fractions, use float variables, but be aware of their drawbacks: large size, slow computation speeds
Use the cast operator e.g. (int)myFloat to convert one variable type to another on the fly.

thank you