[wp-trac] [WordPress Trac] #55942: Add a "value type" parameter to get_option() and get_metadata()
WordPress Trac
noreply at wordpress.org
Sat Apr 29 00:56:27 UTC 2023
#55942: Add a "value type" parameter to get_option() and get_metadata()
-------------------------------------------------+-------------------------
Reporter: azaozz | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 6.3
Component: Options, Meta APIs | Version:
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests needs- | Focuses:
testing | performance
-------------------------------------------------+-------------------------
Comment (by rjasdfiii):
Be aware that MySQL has a "DECIMAL(m,n)" format for things such as
currency, but PHP simply throws them into "DOUBLE". This can lead to
roundoff errors and other rare monetary errors.
MySQL implements DECIMAL using a general decimal package that handles up
to ~65 ''decimal'' digits.
About 40 years ago, IEEE-754 standardized ''binary'' FLOAT and DOUBLE.
Nearly every computer hardware and software manufacturer since then has
adopted these (in addition to other numeric types). Deviating from that
is likely only to confuse.
"1.23" can be represented exactly in MySQL's DECIMAL(m,2). With anyone's
FLOAT, it can be represented only to 24 significant bits. Or 53 for
DOUBLE. Those map to ''approximately'' 7 and 16 significant digits.
"Serialization", if done "correctly", converts the binary numbers into
enough decimal digits so that the subsequent unserialization will produce
exactly the orignal binary value.
Sorry, I don't have a clean solution of how to blend IEEE/PHP/MySQL/WP
when it comes to representing exact monetary value.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/55942#comment:54>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list