[wp-trac] [WordPress Trac] #47454: BC Math isn't used in WordPress core

WordPress Trac noreply at wordpress.org
Thu Jun 6 04:36:11 UTC 2019


#47454: BC Math isn't used in WordPress core
---------------------------------------------------+---------------------
 Reporter:  bronsonquick                           |       Owner:  (none)
     Type:  defect (bug)                           |      Status:  new
 Priority:  normal                                 |   Milestone:  5.3
Component:  Administration                         |     Version:  5.2
 Severity:  normal                                 |  Resolution:
 Keywords:  has-patch site-health has-screenshots  |     Focuses:
---------------------------------------------------+---------------------

Comment (by galbaras):

 Assuming WooCommerce doesn't cast to "int" or use floor(), but instead
 uses round($amount,2), there should be no problem.

 Test:


 {{{
 $x = (int)( 17.535845 );
 var_dump( $x );
 $x = floor( 17.535845 );
 var_dump( $x );
 $x = round( 17.535845, 2 );
 var_dump( $x );
 $x = 7.95 * 0.75; // Simulate a 25% discount on an amount of money
 var_dump( $x );
 }}}

 Results:

 {{{
 int(17)
 float(17)
 float(17.54)
 float(5.9625)
 }}}


 All good when you avoid casting and flooring.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/47454#comment:25>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list