Garmin Forums
Site
Search
User
Site
Search
User
Apps & Software
Outdoor Recreation
Sports & Fitness
Pilots
Developer
Beta Program
German Forum
More
Cancel
Developer
Connect IQ
Connect IQ App Development Discussion
How can I round values?
News & Announcements
Forums
Bug Reports
Wiki
Tags
More
Cancel
Replies
3 replies
Subscribers
15 subscribers
Views
1619 views
Users
0 members are here
Options
Share
More
Cancel
Related
How can I round values?
WIMA75
over 10 years ago
Hello
The Math module does not have a function for rounding values. Is it possible in another way?
Thank you
Marco
Former Member
over 10 years ago
Make own one. You can truncate to integer using .toNumber().
You can this use to made round function, look example:
//trunc(a,1)
var a=9.67;
var b=(a*10).toNumber().toFloat()/10;
// b=9.6
//round(a,1)
var a=9.67;
var b=(a*10+0.5).toNumber().toFloat()/10;
// b=9.7
//round(a,2)
var a=9.673;
var b=(a*100+0.05).toNumber().toFloat()/100;
// b=9.67
Watch to negative!
Cancel
Up
0
Down
Sign in to reply
Cancel
WIMA75
over 10 years ago
thank you.
Cancel
Up
0
Down
Sign in to reply
Cancel
Former Member
over 10 years ago
(value + 0.5).toNumber()
Cancel
Up
0
Down
Sign in to reply
Cancel