openactive / models-php

PHP Models for the OpenActive Opportunity and Booking Specifications
MIT License
6 stars 8 forks source link

PriceSpecification & TaxChargeSpecification rounding issues... #64

Closed jeremyswright closed 3 years ago

jeremyswright commented 3 years ago

Issue Report

I'm seeing rounding issues with the floats in PriceSpecification and TaxChargeSpecification. I'm setting the values to floats with 2 decimal places, but when it comes to serialising the Order/OrderQuote/OrderProposal, it's appending a load of precision issues.

The issue lies in JsonLd->prepareDataForSerialization I believe.

Suggested Resolution

Two possible options:

  1. Move to using integers for financial and percentage values (better solution but more effort)
  2. Change the serialisation/deserialisation routines to handle financial and percentage values as strings.
nickevansuk commented 3 years ago

Thanks for finding this @jeremyswright. We've seen issues around this in other languages too (ref: https://github.com/openactive/modelling-opportunity-data/issues/245). Option 2 above looks like the current favoured approach.

nathansalter commented 3 years ago

I think we need to allow strings in the library, so clients can use things like bcmath without having to parse back to floats and getting rounding errors.

nathansalter commented 3 years ago

This issue has been resolved.