feat(cast): Add precision and rounding mode in FloatCast#10086
feat(cast): Add precision and rounding mode in FloatCast#10086patel-vansh wants to merge 3 commits intocodeigniter4:4.8from
Conversation
michalsn
left a comment
There was a problem hiding this comment.
We currently need both casters. Entity/Cast handles Entity property casting, while DataCaster/Cast handles Model field casting. Even though Model casting has been the preferred approach since v4.5 and Entity casting may be deprecated in the future, Entity casting is still supported, so new float[...] behavior should be consistent in both places.
Also, the new language key is missing.
|
Yes, a useful change. Don't forget to update the user guide examples |
|
I've currently copied the same code for Entity/Cast/FloatCast, if it gets caught by CPD, I think we can call the DataCaster function directly, or maybe tweak a little bit to make it somewhat different. For documentation, I've added a line in Scalar Type Casting section, but I'm unsure if its okay to introduce another section with just float cast showing its parameters or not. @michalsn and @neznaika0 |
Description
This PR adds ability to set precision as well as rounding mode during Float casting.
So, the float cast can be use as following:
I haven't updated the user guide yet (that's why the PR is in draft), as before updating the user guide, I wanted others to give their opinion on the implementation.
Also, I had one question, I saw that the casts are defined at two places in
system/folder:I don't know why there are two different implementation of similar classes, that's why for now, I haven't added the rounding code in
Entity/Cast/FloatCast.php, but if its needed, then I'll add (however, Idk if the CPD Github Action will catch it and fail)Checklist: