- 21 Sep 2023
- 1 Minute to read
- Print
- DarkLight
Rounding Numbers up to the Nearest .XXX5
- Updated on 21 Sep 2023
- 1 Minute to read
- Print
- DarkLight
Overview
Example Lab Details | |
Version | 6.9.2 |
Root Folder | Example Lab - Rounding Numbers |
Modules | None |
Dependencies | None |
This Example Lab project demonstrates how to round a number up to the nearest X.XXX5 place. This project does not function to round numbers conventionally.
Explanation
This Example Lab project rounds numbers up to the nearest X.XXX5. For example, 1.0006 would round to 1.0010. It only rounds numbers up, not down, to either the nearest .0005 if the 4th decimal place is under 5 but not zero, or it will round up to ten if the fourth decimal place is above five.
This project works by showing a Form that requests the user to input a number with four decimal places (the Form will round the number to four decimal places if more than four are inserted). The number is then sent to a Sub-Flow titled "Round Sub Flow", where the logic to round the number is carried out. The Sub-Flow determines what number is in the 4th decimal place, evaluating if the number needs to be increased and, if so, by how much. The Sub-Flow contains a truth table within it to process this evaluation.
If the input number is 6.0037, the Flow would isolate the 7 and run it against the truth table. Since 7 will need to be rounded up, the truth table would output how much to add to the number in order for it to reach 10. The Flow then uses the Evaluate Dynamic Expression step to evaluate ((Number*10000)+Result)/10000, returning the number back to its original form so that it can be passed out of the Sub-Flow and shown to the user in the main Flow.