The problem is in the returned values, not in Mojo::JSON itself.
Both modules returns strings instead of numbers, to solve that, I could
work with Math::BigInt methods, but I could not find any Math::BigFloat
method.
Here is:
--------------8<--------------
use Mojo::JSON 'j';
use Math::BigFloat;
use Math::BigInt;
my $float = Math::BigFloat->new(12.34)->bstr;
my $int = Math::BigInt->new(123)->numify;
print j {float => $float+0, int => $int}; # {"int":123,"float":12.34}
-------------->8--------------
I don't like the +0 solution in this case, but I couldn't figure out
another one.
Let's see if anyone has any other alternative or correct solution for that.
Regards,
On Mon, Jun 30, 2014 at 3:12 PM, Tekki <[email protected]> wrote:
> Mojo::JSON encodes Math::BigFloat and Math::BigInt as strings. Example:
>
> use Mojo::JSON 'encode_json';
> use Math::BigFloat;
> use Math::BigInt;
>
> my $float = Math::BigFloat->new(12.34);
> my $int = Math::BigInt->new(123);
>
> print encode_json {float => $float, int => $int}; #
> {"int":"123","float":"12.34"}
>
> Wouldn't it make sense to return them as numbers instead?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Mojolicious" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>
--
Gabriel Vieira
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.