Keats / tera

A template engine for Rust based on Jinja2/Django
http://keats.github.io/tera/
MIT License
3.36k stars 280 forks source link

round filter: perform cast to i128 if precision is 0 #899

Open Raymi306 opened 5 months ago

Raymi306 commented 5 months ago

For issue #889

Perform an additional check on precision, and cast to an integer if it is 0.

Raymi306 commented 5 months ago

I truthfully am not super familiar with serde_json, perhaps i need a better test for this. I originally was using i64 but thought that i128 might better handle some of the big numbers an f64 might represent.

On Mon, Feb 12, 2024, 8:21 AM Vincent Prouillet @.***> wrote:

@.**** commented on this pull request.

In src/builtins/filters/number.rs https://github.com/Keats/tera/pull/899#discussion_r1486172468:

          only common, ceil and floor are allowed",
  • method
  • ))),
  • method
  • )))
  • }
  • };
  • // Do we need to return an integer or a float?
  • if precision == 0 {
  • Ok(to_value(intermediate_result as i128).unwrap())

isn't i128 in serde_json converted to a string?

— Reply to this email directly, view it on GitHub https://github.com/Keats/tera/pull/899#pullrequestreview-1875223175, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKYK2OTOGOBEAALFCVQJZL3YTIJMHAVCNFSM6AAAAABDCMTXASVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTQNZVGIZDGMJXGU . You are receiving this because you authored the thread.Message ID: @.***>