Advertisement
Guest User

Untitled

a guest
Sep 13th, 2012
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.61 KB | None | 0 0
  1. /*
  2.  *
  3.  *  jFraction by jameskmonger
  4.  *
  5.  */
  6.  
  7. /*
  8.  *
  9.  * split
  10.  * strsrc - the string to split up
  11.  * strdest - the string array to store split strings in
  12.  * delimiter - the character to split by
  13.  *
  14.  * Split a selected string into an array
  15.  *
  16.  */
  17. static stock split(const strsrc[], strdest[][], delimiter)
  18. {
  19.     new i, li;
  20.     new count;
  21.     new len;
  22.     while(i <= strlen(strsrc))
  23.     {
  24.         if(strsrc[i] == delimiter || i == strlen(strsrc))
  25.         {
  26.             len = strmid(strdest[count], strsrc, li, i, 128);
  27.             strdest[count][len] = 0;
  28.             li = i+1;
  29.             count++;
  30.         }
  31.         i++;
  32.     }
  33.     return 1;
  34. }
  35.  
  36. /*
  37.  *
  38.  * str_count
  39.  * string - the string to be searched
  40.  * count - the character to look for
  41.  *
  42.  * Count and return the number of count[] in string[]
  43.  *
  44.  */
  45. static stock str_count(const string[], const count[]) {
  46.     new i, num;
  47.     if(strlen(count) == 1) {
  48.         while(i <= strlen(string)) {
  49.             if(string[i] == count[0]) {
  50.                 num++;
  51.             }
  52.             i++;
  53.         }
  54.     }
  55.     return num;
  56. }
  57.  
  58. /*
  59.  *
  60.  * fractionToDecimal
  61.  * fraction - the inputted fraction
  62.  * result - the float to store the decimal result in
  63.  *
  64.  * Take a fraction as a string and return it as a decimal
  65.  *
  66.  */
  67. stock fractionToDecimal(const fraction[], &Float:result) {
  68.     new number_string[2][26],
  69.         Float:number_val[2];
  70.  
  71.     if(str_count(fraction, "/") == 1) {
  72.         if(strlen(fraction) < 26) {
  73.             split(fraction, number_string, '/');
  74.             number_val[0] = floatstr(number_string[0]);
  75.             number_val[1] = floatstr(number_string[1]);
  76.             result = floatdiv(number_val[0], number_val[1]);
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement