Miseryk

ReMake % + Math.Trunc

Jan 4th, 2021
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Truncar(Dividendo, Divisor) //Math.Trunc, ~~ - Truncate
  2. {
  3.     var Cont = 0;
  4.    
  5.     while (1)
  6.     {
  7.         Cont++;
  8.        
  9.         if (Divisor * Cont > Dividendo)
  10.         {
  11.             Cont--;
  12.             break;
  13.         }
  14.     }
  15.    
  16.     return (Dividendo / Divisor) - Cont;
  17. }
  18.  
  19. function Resto(Dividendo, Divisor) //% - Module
  20. {
  21.     //return Dividendo - (~~(Dividendo / Divisor) * Divisor);
  22.     return Dividendo - (((Dividendo / Divisor) - Truncar(Dividendo, Divisor)) * Divisor);
  23. }
  24.  
  25. var resultado_resto = Resto(25, 3);
  26. //resultado_resto = Resto(25.5, 3.3);
  27.  
  28. console.log(resultado_resto);
Advertisement
Add Comment
Please, Sign In to add comment