Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *
- * jFraction by jameskmonger
- *
- */
- /*
- *
- * split
- * strsrc - the string to split up
- * strdest - the string array to store split strings in
- * delimiter - the character to split by
- *
- * Split a selected string into an array
- *
- */
- static stock split(const strsrc[], strdest[][], delimiter)
- {
- new i, li;
- new count;
- new len;
- while(i <= strlen(strsrc))
- {
- if(strsrc[i] == delimiter || i == strlen(strsrc))
- {
- len = strmid(strdest[count], strsrc, li, i, 128);
- strdest[count][len] = 0;
- li = i+1;
- count++;
- }
- i++;
- }
- return 1;
- }
- /*
- *
- * str_count
- * string - the string to be searched
- * count - the character to look for
- *
- * Count and return the number of count[] in string[]
- *
- */
- static stock str_count(const string[], const count[]) {
- new i, num;
- if(strlen(count) == 1) {
- while(i <= strlen(string)) {
- if(string[i] == count[0]) {
- num++;
- }
- i++;
- }
- }
- return num;
- }
- /*
- *
- * fractionToDecimal
- * fraction - the inputted fraction
- * result - the float to store the decimal result in
- *
- * Take a fraction as a string and return it as a decimal
- *
- */
- stock fractionToDecimal(const fraction[], &Float:result) {
- new number_string[2][26],
- Float:number_val[2];
- if(str_count(fraction, "/") == 1) {
- if(strlen(fraction) < 26) {
- split(fraction, number_string, '/');
- number_val[0] = floatstr(number_string[0]);
- number_val[1] = floatstr(number_string[1]);
- result = floatdiv(number_val[0], number_val[1]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement