Rounding With Units

Rounding With Units - Question regarding the use of units and the round(x) function - Messages

#1 Posted: 6/22/2017 8:38:01 PM
Wesly Osornio Centerwall

Wesly Osornio Centerwall

0 likes in 3 posts.

Group: User

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?

#2 Posted: 6/23/2017 5:08:32 AM
Davide Carpi

Davide Carpi

1416 likes in 2873 posts.

Group: Moderator

Hi [userlink]wes.oc[/userlink],

Wrote

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:

  1. divide and multiply for the unit
    2017-06-23 09_57_07-SMath Studio - [roundm.sm_].png

  2. change the base units system (see here how)



Wrote

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:

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)
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
Wesly Osornio Centerwall

Wesly Osornio Centerwall

0 likes in 3 posts.

Group: User

Thank you very much for an excellent response Davide.
  • New Posts New Posts
  • No New Posts No New Posts