Hello All,
I have a question. I need to get a calculation with a certain amount of precision. Since you can't define datatypes in MEL I am stuck. Take a look at my MEL trace:
MelTrace] results>"150"
MelTrace] execute>call VAL("150")
MelTrace] results>150
MelTrace] execute>150 / 3025
MelTrace] results>0.05
When I get out my calculator and divide 150 / 3025 I get: 0.0495867768595041. In order to get the calculation I need I need the value to not get rounded by default. Has anyone else run into this and found a way around it?
Thanks,
Brad
I tried the same thing, MEL Trace results were similar but the field appears to be holding 6 digits past the decimal, see below. I would check the calculation all the way through and see if it is really a problem. If it is you can try appending a few zeros to each value and moving the decimal place back later in the calculation.
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] Fire trigger: val("150")/3025
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] execute>>call VAL("150")
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] results>>150
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] execute>>150 / 3025
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] results>>0.05
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] execute>>end
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] results>>0.05
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] execute>>Done with trigger
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace]
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] results>"0.05"
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] execute>call EVAL("0.05")
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] >>
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] Fire trigger: 0.05
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] execute>>end
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] results>>0.05
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] execute>>Done with trigger
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace]
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] results>"0.05"
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] execute>1 + 2
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] results>3
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] execute>CMDINT = 3
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] results>3
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] execute>call SIZE(Array)
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] results>3
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] execute>3 <= 3 04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] results>TRUE
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] execute>for TRUE
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] results>TRUE
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] execute>Array[3]
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] results>"userok(document.hold_field)"
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] execute>call EVAL("userok(document.hold_field)")
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] >>
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] Fire trigger: userok(document.hold_field)
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] execute>>Document.hold_field
04/13/2016 16:08:31.288 INFO Process Id #3348 ML Thread [MelTrace] results>>"0.049587"
04/13/2016 16:08:31.289 INFO Process Id #3348 ML Thread [MelTrace] execute>>call USEROK("0.049587")
04/13/2016 16:08:33.167 INFO Process Id #3348 ML Thread [MelTrace] results>>FALSE
04/13/2016 16:08:33.167 INFO Process Id #3348 ML Thread [MelTrace] execute>>end
04/13/2016 16:08:33.167 INFO Process Id #3348 ML Thread [MelTrace] results>>FALSE
04/13/2016 16:08:33.167 INFO Process Id #3348 ML Thread [MelTrace] execute>>Done with trigger
Pass the value to a string.
document.results = str(150 / 3025) /* Results should be 0.0495867768595041 */
document.results = truncate(document.results, 6) /* For 6 digits after the decimal point 0.049586*/
Then if you want fewer digits after the decimal point, use the Truncate(number, digits)
or Round(number, digits) function.
Pretty sure this will work for you.
-James
How much precision do you need?
Why not simply multiply the numerator by 1000 prior to the division function? That would force 3 digits of accuracy. Just remember, you will not be seeing 0.0495 but 40.95 - but that may be a quick solution if your next steps are to have some "if" statements to give certain messages.
Thank you for your response. I wasn't able to get the needed value by passing the calculation to a string. However, when I did this it did work:
document.results = eval(150 / 3025)
The problem is I can't hard code values, I need to put variables in there. So I tried this:
local heightsqred = document.height ^ 2
local bmidivide = eval(document.weight / heightsqred)
In the example above document.height is 55, so if squared you get 3025 and document.weight is 150. When I run the code this is what I get in my trace:
[MelTrace] results> "150"
[MelTrace] execute> "150" / 3025
[MelTrace] results> 0.05
[MelTrace] execute> call EVAL(0.05)
[MelTrace] results> 0.05
[MelTrace] execute> BMIDIVIDE = 0.05
[MelTrace] results> 0.05
So it looks like the division happens before the eval() if you have variables inside of the eval().
Thank you to everyone for replying. The reason I was doing this is I was given the task of getting our BMI calculator in line with the NIH website's calculator. My initial thought after looking at MEL traces is that it was a precision issue. After looking at the javascript in the NIH page it looks like their calculator manipulates the value (up) a bit depending on conditions. I was able to recreate their functions in MEL. Thank you for all the help. It is useful though to know that sometimes Centricity may round when you aren't expecting it.