DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Round Function Error

Solved!
Go to solution

Hello,

 

i noticed an error in my script using the in-build Round() function. Why do these 2 statements output the same result (at least for me using DIAdem 2022 Q4):

 

Logfiledel
Logfilewrite Round(1.5) ' Output = 2
Logfilewrite Round(2.5) ' Output = 2 (?)

 

Is this a bug or what could be the problem? Obviously Round(2.5) should output 3 and not 2.

 


Thanks in advanced for your support!

0 Kudos
Message 1 of 4
(807 Views)

Microsoft follows IEEE 754 standard - round half to even.  So it is working perfectly to the standard.

0 Kudos
Message 2 of 4
(781 Views)

Thanks for your reply.

 

Is there an in-build function to round 'mathematically', which means:

  • round up from 0.5 <= x < 1 --> e.g. Round(2.5) = 3
  • round down from 0 <= x < 0.5  --> e.g. Round(2.4) = 2

 

0 Kudos
Message 3 of 4
(733 Views)
Solution
Accepted by topic author mt90354

The built-in rounding in VBS is just that one. 

Some options:

1. Try:

Call LogFileWrite(FormatNumber(1.5, 0))
Call LogFileWrite(FormatNumber(2.5, 0))

2. You can implement your own logic for rounding

3. DIAdem has built in whole channel rounding:

gsklyr_0-1676301430018.png

You can record it to get the script with the needed options

Message 4 of 4
(725 Views)