Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline wes.oc  
#1 Posted : 23 June 2017 02:38:01(UTC)
wes.oc

Rank: Newbie

Groups: Registered
Joined: 11/02/2017(UTC)
Posts: 3
United States
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?

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline Davide Carpi  
#2 Posted : 23 June 2017 11:08:32(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,639
Man
Italy
Location: Italy

Was thanked: 1323 time(s) in 873 post(s)
Hi wes.oc Offline ,

Originally Posted by: wes.oc Go to Quoted Post
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)



Originally Posted by: wes.oc Go to Quoted Post
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)

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
Offline wes.oc  
#3 Posted : 23 June 2017 18:36:58(UTC)
wes.oc

Rank: Newbie

Groups: Registered
Joined: 11/02/2017(UTC)
Posts: 3
United States
Location: Oregon

Thank you very much for an excellent response Davide.
Users browsing this topic
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.