Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
1 answer
91 views

Factorial Fraction using PHP

Can someone explain to me how we can get the factorial of fractional numbers using functions? A result like this 1! + 2 / 2! + 3 / 3! + ....... + 10/10!
Saman22's user avatar
  • 21
-2 votes
2 answers
2k views

How to convert between decimals and fractions in PHP

I am trying to multiply numbers by 2 and these numbers are either whole numbers or fractions. I am pulling in these numbers dynamically through ACF fields on WordPress as text field. But some of these ...
Colleen Bowes's user avatar
0 votes
2 answers
95 views

How optimize function of counting fractions?

I write function which gets one array from 3 elements (integer, numerator and denominator). It calculate wrong fractions to normal (numerator>denominator). How optimize this function? I understand ...
penewunuh's user avatar
1 vote
3 answers
102 views

PHP Memory Exhausted Error with simple fractions

I am using this library to work with fractions in PHP. This works fine but sometimes, I have to loop over a lot of values and this results in the following error: Allowed memory size of 134217728 ...
iKnowNothing's user avatar
0 votes
2 answers
297 views

How to sort an array contains complex strings with fractions in php?

I have the following values in an array, $values = array( "1/4x1/4x1", "1/2x1/2x1", "3/4x3/4x1", "1/4x1/4x2", "1/2x1/2x2", ...
Niroshan's user avatar
1 vote
0 answers
136 views

Find opened / closed parenthesis of nested fractions

For a non-commercial math site I would need a function with which I can detect nested fractions from a string and then apply the following method to the numerator / the denominator var a = nerdamer('...
Michael Frischauf's user avatar
1 vote
2 answers
678 views

How to sort an array of Imperial values (inches with fractions)?

I am using the following code to sort the values using native sort algorithm. usort($this->_items, function($a, $b) { return strnatcasecmp($a['label'], $b['label']);}); But the issue is it is not ...
magento2new's user avatar
-1 votes
1 answer
591 views

php switch case statement to handle ranges with decimals / fractions

Using a case switch, how would I test to see if a decimal value is within a range? This code appears to only check whole numbers. Here is my code in an attempt to check decimals / fractions. $...
Damien's user avatar
  • 157
0 votes
2 answers
75 views

Fix for convert fraction short PHP snippet, issue with calculation converting a fraction to more readable format

Here is the problem, when it encounters fractions like: 300/10 instead of giving a result of "30" the following code gives me: 1/0 $tokens = explode('/', $value); while ($tokens[0] % 10 == 0) { ...
htfree's user avatar
  • 361
0 votes
2 answers
1k views

Decimal odds conversion timeout

I'm trying to convert from decimal to fraction sporting odds. I have found via a search a PHP function which works well, but certain decimals cause problems, such as 2.1 which maxs out the server: ...
Alan A's user avatar
  • 2,551
-1 votes
4 answers
215 views

Decimal to fraction won't work for negative numbers

I have this script that coverts decimals to fractions: function toFraction($number){ $numerator = 1; $denominator = 0; for(; $numerator < 1000; $numerator++){ $temp = $...
user1981730's user avatar
10 votes
2 answers
1k views

Convert Fractions to Words

I'd like to know if there is a neat way to convert 1/2, 1/4, 5/8 into words (half, quarter, five eighths) using PHP. I've got a product data feed, and need to create a clean URL for each product ...
Alexander Holsgrove's user avatar
-1 votes
1 answer
1k views

How to store a fraction as a character in MySQL so it can be outputted within text [closed]

I am trying to store the fraction 3/5 (three fifths) as a character in MySQL so that it outputs in php like the symbol ½ within a line of text. I am using phpMyAdmin. The code for the fraction 3/5 is:...
TedtheBear's user avatar
1 vote
2 answers
4k views

Function to round mm to the nearest 32nd of an inch

I really badly need a php function that will convert a millimeter into a fraction (in inches). For example: 16mm = 5/8 of an inch 321mm = 12 41⁄64 inches I have searched high and low for any php ...
LargeTuna's user avatar
  • 2,834
1 vote
1 answer
1k views

Regex - Identify Fractions

I need to identify a fraction from a form field in a recipe database using a Regex. Ingredients will be entered in a two part form fields. Field one is the amount, Field two is the ingredient. I then ...
user1008960's user avatar

15 30 50 per page