Fraction module give floating point denominator value on createFromDecimal($value) function

Created on 9 April 2024, 9 months ago
Updated 10 April 2024, 9 months ago

Problem/Motivation

 The Fraction module is currently displaying the denominator as a floating-point number "1.0000" in the Windows OS. However, the Fraction module should ideally provide integer values for both the numerator and denominator.

Steps to reproduce

Install "XAMPP" server on windows os. Then install "farmOS or Drupal" with Fraction module. when you create quantity in "farmOS log" it will show primitive value error. Then you dig in to code this problem is coming from Fraction Module (only windows). On debugging this Fraction module it give floating point value on denominator by calling "bcpow(10,$precision);" function. Then you look php manual it says above php7.3 "bcpow()" function will give output as floating point number.

Proposed resolution

Temporary:

We should run " bcpow(string $num, string $exponent, ?int $scale = null): string" this function with "$scale" as 0 ("bcpow(10,0,0);") in windows cmd prmt. it will clear problem in all of using place of current php instance.

Permanant:

Please change this "bcpow(10,$precision);" code to "bcpow(10,$precision,0);" in Fraction module(createFromDecimal).

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

2.3

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States m.stenta

    Thanks for reporting this @aathi179 (and for approving it @fjgarlin)!

    This is an interesting bug, and I wonder why it works differently on Windows. I would like to get confirmation from at least one other Windows user that this is indeed an issue.

    @aathi179 I wonder if you could tell me what you get when you run bcscale() in your environment. In Linux I get 0.

    I doubt that Windows defaults to something other than 0, but maybe something in your environment is setting it to something else.

    Nevertheless, the fact that bcpow() falls back to using the scale from bcscale() means this would be an issue in any environment with a non-zero scale. So we probably should set it explicitly to zero in our code.

    The other thing that comes to mind: our code falls back on using pow() if BCMath is not installed, but pow() doesn't have an argument for scale. So I wonder how this might work differently without BCMath, and if there is risk of a similar issue.

  • Sir, sorry to test with my pc now because i was already run this `bcpow(10,0,0);` code on cmd prompt. i will test with another laptop and update here. sorry for the delayed response i didn't get any response from drupal accidentally i checked this one.

Production build 0.71.5 2024