Comments (3)
I have been debugging my test script, first without the use Locale::CLDR
(which succeeds) and then with the use Locale::CLDR
(which fails). I see some strange things, that I can't quite explain, but there is some difference.
Without use Locale::CLDR
On line 260 of the file CLDR/Number/Role/Format.pm, you call Math::BigFloat->($num)
. As $num
is the integer value 42
, Math::BigFloat
creates a Math::BigInt
and stores that one internally. The call to ffround
on this new object will actually result in a call to function Math::BigFloat::bfround
(note the difference in the first character of the function name!) and this call will actually succeed.
The module Math::BigFloat also has a module variable called $downgrade
. When Locale::CLDR is not loaded, this variable has the value undef
.
With use Locale::CLDR
On line 260 of the file CLDR/Number/Role/Format.pm, you call Math::BigFloat->($num)
. As $num
is the integer value 42
, Math::BigFloat
creates a Math::BigInt
and stores that one internally. The call to ffround
on this new object in this case does not result in a call to function Math::BigFloat::bfround
(note the difference in the first character of the function name!), but indeed tries to call ffround
on the Math::BigInt
that was stored internally and that function does not exist.
When the module Locale::CLDR
is loaded, the module Math::BigFloat
variable $downgrade
has the value Math::BigInt
. This probably makes the difference in handling the ffround
.
Now examining the code of Math::BigFloat
further, there is only one location where the modules variable $downgrade
is set, and that is in its import
function when one of the arguments is 'downgrade'
(which does not seem to be documented on cpan BTW). The fact that $downgrade
is set when using Locale::CDLR
is because the module Locale::CLDR::NumberFormatter
uses bignum
.
My proposal would be to change the following code in the function CLDR::Number::Role::Format::_format_number
(lines 258 to 264)
else {
# round half to even
$rounded = Math::BigFloat->new($num)->ffround(
-$self->maximum_fraction_digits,
'even'
)->babs->bstr;
}
to
else {
# round half to even
my $mbf = Math::BigFloat->new($num);
if (ref $mbf eq 'Math::BigInt') # Needed in case another module uses Math::BigFloat with the 'downgrade' option
{
$rounded = $mbf->bfround(
-$self->maximum_fraction_digits,
'even'
);
}
else
{
$rounded = $mbf->ffround(
-$self->maximum_fraction_digits,
'even'
);
}
$rounded = $rounded->babs->bstr;
}
Would it be possible to make this change in the repository and create a new release of CLDR::Number in metacpan? Of course I can locally patch it, but that would not make it available to other users of this module.
from cldr-number-pm5.
Hi Marcel, thanks for reporting this. I’m not sure why Locale::CLDR
causes CLDR::Number
to break. I do wonder why ffround
is associated with Math::BigInt
in your error message, as it’s actually part of Math::BigFloat
which I’m using. I’m not able to help troubleshoot at this time but would happily accept any fixes. I’m not familiar with any modern CLDR-related modules in CPAN, although I can show you how to easily accomplish this in JavaScript in case your project uses frontend code.
from cldr-number-pm5.
I will try to find out the actual cause of this (will also contact the developer of Locale::CLDR). I will let you know the outcome and if I am able to make a fix for it.
from cldr-number-pm5.
Related Issues (20)
- support different rounding modes
- round half-even with rounding increment
- add algorithmic (non-decimal) numbering systems
- support CLDR v27 HOT 3
- locales should inherit from defined parent locales when available
- support spelled-out currencies
- add minimum grouping digits HOT 5
- load locale data for each locale from a different module
- deprecate mutable locales
- We need plurals data from CLDR. HOT 1
- add FAQ about fallback for non-existant locales HOT 1
- test upgrade using preliminary CLDR v28 data HOT 5
- infinity and NaN are not supported by all perls
- use Math::BigFloat as much as possible
- remove Math::BigFloat for Inf/NaN checking HOT 1
- Tests fail (with latest Moo?) HOT 3
- upgrade to CLDR v29
- Moo::Role-related bug in Perl 5.8.1 through 5.8.3
- improve docs for a broader audience
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cldr-number-pm5.