FHIR Chat · how do we achieve Math.round() in fhirpath · implementers

Stream: implementers

Topic: how do we achieve Math.round() in fhirpath


view this post on Zulip Rajesh (Jun 02 2021 at 16:46):

Given a number, How can I round off the number exactly like Math.round() function from javascript using fhirpath.js?
console.log(Math.round(1.4)); // prints 1
console.log(Math.round(1.6)); // prints 2
console.log(Math.round(1.5)); // prints 2

I saw below functions in fhirpath
ceiling() returns the integer greater than or equal to the input.
floor() returns the first integer less than or equal to the input.
To use above functions in the expression, I should know the fractional part of input upfront while preparing the fhirpath expression.

I want to write a fhirpath expression,
It should return the smallest integer that is still greater than the input when the fractional part is >=.5
It should return the largest possible integer that is still smaller than the number we passed when the fractional part is <=.4

view this post on Zulip Lloyd McKenzie (Jun 02 2021 at 17:28):

You might want to ask on #fhirpath


Last updated: Apr 12 2022 at 19:14 UTC