Advertisement
DManstrator

DivideExactly

Nov 10th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. //Teilt a durch b und gibt das Ergebnis auf n Stellen genau an.
  2. global func DivideExactly(int a, int b, int n)
  3. {
  4. if(!b) return "Infinity";
  5. var szResult = Format("%d",a/b);
  6. a %= b;
  7. a *= 10;
  8.  
  9. if(!a||!n) return szResult;
  10. else szResult = Format("%s.",szResult);
  11.  
  12. for(; n>0; n--)
  13. {
  14. if(!a) break;
  15.  
  16. szResult = Format("%s%d",szResult,a/b);
  17. a %= b;
  18. a *= 10;
  19. }
  20.  
  21. return szResult;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement