Kwarde

RoundFloat include

Feb 27th, 2011
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.95 KB | None | 0 0
  1. #if !defined _samp_included
  2.     #include <a_samp>
  3. #endif
  4. #if defined _roundfloat_included
  5.     #endinput
  6. #endif
  7. #define _roundfloat_included
  8.  
  9. stock RoundFloat(Float:input)
  10. {
  11.     new tmpstr[50],
  12.         split[2][25],
  13.         tmp[3]
  14.     ;
  15.     format(tmpstr, 50, "%.02f", input);
  16.     for(new i = 0, l = strlen(tmpstr); i < l; i++)
  17.     {
  18.         if(tmpstr[i] == '.')
  19.         {
  20.             strins(split[0], tmpstr, 0, i-1);
  21.             strins(split[1], tmpstr[i+1], 0);
  22.         }
  23.     }
  24.     tmp[0] = strval(split[0]);
  25.     tmp[1] = strval(split[1]);
  26.     if(tmp[1] >= 0 && tmp[1] < 10){
  27.         if(tmp[1] >= 0 && tmp[1] < 5) tmp[1] = 0;
  28.         if(tmp[1] >= 5) tmp[1] = 10;
  29.     }
  30.     else if(tmp[1] >= 10 && tmp[1] < 20){
  31.         if(tmp[1] >= 10 && tmp[1] < 15) tmp[1] = 10;
  32.         if(tmp[1] >= 15) tmp[1] = 20;
  33.     }
  34.     else if(tmp[1] >= 20 && tmp[1] < 30){
  35.         if(tmp[1] >= 20 && tmp[1] < 25) tmp[1] = 20;
  36.         if(tmp[1] >= 25) tmp[1] = 30;
  37.     }
  38.     else if(tmp[1] >= 30 && tmp[1] < 40){
  39.         if(tmp[1] >= 30 && tmp[1] < 35) tmp[1] = 30;
  40.         if(tmp[1] >= 35) tmp[1] = 40;
  41.     }
  42.     else if(tmp[1] >= 40 && tmp[1] < 50){
  43.         if(tmp[1] >= 40 && tmp[1] < 45) tmp[1] = 40;
  44.         if(tmp[1] >= 45) tmp[1] = 50;
  45.     }
  46.     else if(tmp[1] >= 50 && tmp[1] < 60){
  47.         if(tmp[1] >= 50 && tmp[1] < 55) tmp[1] = 50;
  48.         if(tmp[1] >= 55) tmp[1] = 60;
  49.     }
  50.     else if(tmp[1] >= 60 && tmp[1] < 70){
  51.         if(tmp[1] >= 60 && tmp[1] < 65) tmp[1] = 60;
  52.         if(tmp[1] >= 65) tmp[1] = 70;
  53.     }
  54.     else if(tmp[1] >= 70 && tmp[1] < 80){
  55.         if(tmp[1] >= 80 && tmp[1] < 85) tmp[1] = 80;
  56.         if(tmp[1] >= 85) tmp[1] = 90;
  57.     }
  58.     else if(tmp[1] >= 80 && tmp[1] < 90){
  59.         if(tmp[1] >= 80 && tmp[1] < 95) tmp[1] = 80;
  60.         if(tmp[1] >= 95) tmp[1] = 90;
  61.     }
  62.     else if(tmp[1] >= 90 && tmp[1] < 100){
  63.         if(tmp[1] >= 90 && tmp[1] < 95) tmp[1] = 90;
  64.         if(tmp[1] >= 95){
  65.             tmp[1] = 0;
  66.             tmp[0] = tmp[0] + 1;
  67.         }
  68.     }
  69.     else if(tmp[1] >= 100){
  70.         tmp[1] = 0;
  71.         tmp[0] = tmp[0] + 1;
  72.     }
  73.     format(tmpstr, 50, "%d.%d", tmp[0], tmp[1]);
  74.     return tmpstr;
  75. }
Add Comment
Please, Sign In to add comment