1 Pages (3 items)
Rounding With Units - Question regarding the use of units and the round(x) function - Messages
#1 Posted: 6/22/2017 8:38:01 PM
When I use the round(x,n) function with units, the result is not an integer.
Note that I am putting my result in (ft) and not (meters). Not sure if that maters.
For example:
round(12.8,0) = 13.1234 ft (This function is set to 4 dec. places, if i set it to 0 dec. places it will show 13.
What I want to do is round to the nearest 0.5
if round(X,0) < X
X:=round(x,0)
else
X:=round(x,0)+0.5
This should give me 13 for 12.8 and 12.5 for 12.3, but it gives me 13.1234 and 12.6234 (units in ft)
Is there an issue with round(x,n) and units?
Note that I am putting my result in (ft) and not (meters). Not sure if that maters.
For example:
round(12.8,0) = 13.1234 ft (This function is set to 4 dec. places, if i set it to 0 dec. places it will show 13.
What I want to do is round to the nearest 0.5
if round(X,0) < X
X:=round(x,0)
else
X:=round(x,0)+0.5
This should give me 13 for 12.8 and 12.5 for 12.3, but it gives me 13.1234 and 12.6234 (units in ft)
Is there an issue with round(x,n) and units?
#2 Posted: 6/23/2017 5:08:32 AM
Hi [userlink]wes.oc[/userlink],
It matters; once defined, values are converted in base units. This means that if the units system is Metric, you are rounding the value in meters instead of feet.
To make it working, there are 2 ways:
round(value,n) rounds a value to the n-th decimal digit, what you are looking for instead is a function that rounds to a multiple of a generic number, and it is really easy to have it:
![2017-06-23 10_05_20-SMath Studio - [roundm.sm_].png](/en-US/file/ngpcBy/2017-06-23-10_05_20-SMath-Studio---_roundm_sm___png)
note that this works indipendently from your units system (just place 'ft in the rightmost placeholder if you are using imperial units with base SI system and vice-versa)
WroteWhen I use the round(x,n) function with units, the result is not an integer.
Note that I am putting my result in (ft) and not (meters). Not sure if that maters.
It matters; once defined, values are converted in base units. This means that if the units system is Metric, you are rounding the value in meters instead of feet.
To make it working, there are 2 ways:
- divide and multiply for the unit
- change the base units system (see here how)
WroteWhat I want to do is round to the nearest 0.5
if round(X,0) < X
X:=round(x,0)
else
X:=round(x,0)+0.5
This should give me 13 for 12.8 and 12.5 for 12.3, but it gives me 13.1234 and 12.6234 (units in ft)
round(value,n) rounds a value to the n-th decimal digit, what you are looking for instead is a function that rounds to a multiple of a generic number, and it is really easy to have it:
note that this works indipendently from your units system (just place 'ft in the rightmost placeholder if you are using imperial units with base SI system and vice-versa)
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#3 Posted: 6/23/2017 12:36:58 PM
Thank you very much for an excellent response Davide.
1 Pages (3 items)
-
New Posts
-
No New Posts