[Include] jFraction - ingame fractions with ease!
#1

Ever wanted to easily handle a fraction? Now you can!

How to include
To use, just include the include file into your script! (I saved it as jInclude.inc in pawno/includes, so I used the below line in my script)
pawn Код:
#include <jFraction>


How to use
And then you can use it like so:
pawn Код:
new Float:decimal;
fractionToDecimal("1/20", decimal);
"decimal" will then be equal to 0.5.



Examples
pawn Код:
new Float:dec;
fractionToDecimal("1/5", dec);
printf("dec = %f", dec);
fractionToDecimal("3/10", dec);
printf("dec = %0.1f", dec);
The above script, when ran, will say "dec = 0.200000" and then "dec = 0.3".



Download
Pastebin




Credits
  • jameskmonger (me!)
  • Whoever created the split function


This is my first include, I hope you enjoy it.
Reply
#2

I don't see how this is useful in any way, but other then that nice job.
Reply
#3

Instead of using a string why not just have two parameters, one being the numerator, and the other one being the denominator?
Reply
#4

It could be used to handle player commands. You could have an option for a player to pay another player a certain fraction of his money. Extract the fraction string and use this command to get the decimal value. Divide the player's money by the decimal value and then remove it from player A and give it to player B.

Also, it supports up to 24 numbers and one slash (so 1/11111111111111111111111 is possible, I think).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)