Rank: Newbie
Groups: Registered
Joined: 11/02/2017(UTC) Posts: 3 Location: Oregon
|
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?
|
|
|
|
Rank: Advanced Member Groups: Registered, Advanced Member Joined: 13/01/2012(UTC) Posts: 2,639 Location: Italy Was thanked: 1323 time(s) in 873 post(s)
|
Hi
wes.oc
, Originally Posted by: wes.oc 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. 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)
Originally Posted by: wes.oc 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) 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) Edited by user 24 June 2017 03:08:12(UTC)
| Reason: marked as solved |
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects |
|
|
|
Rank: Newbie
Groups: Registered
Joined: 11/02/2017(UTC) Posts: 3 Location: Oregon
|
Thank you very much for an excellent response Davide.
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.