Round off Steps Perc. Km and Miles and other tags

Perhaps you can use this.

*** ROUND OFF *** [tag] is your expression
([tag]%1>0.5?[tag]+1-[tag]%1:[tag]-[tag]%1) round numbers
([tag]*10%1>0.5?[tag]+0.1-[tag]*10%1/10:[tag]-[tag]*10%1/10) 1 decimal

** Steps above 100% ** round number
(([SC]/([SC_GOAL]/100))%1>0.5?([SC]/([SC_GOAL]/100))+1-([SC]/([SC_GOAL]/100))%1:([SC]/([SC_GOAL]/100))-([SC]/([SC_GOAL]/100))%1)
** Steps above 100% ** 1 decimal
(([SC]/([SC_GOAL]/100))*10%1>0.99?([SC]/([SC_GOAL]/100))+0.1-([SC]/([SC_GOAL]/100))*10%1/10:([SC]/([SC_GOAL]/100))-([SC]/([SC_GOAL]/100))*10%1/10)

** KM ** 1 decimal
(([SC]*0.000762)*10%1>0.5?([SC]*0.000762)+0.1-([SC]*0.000762)*10%1/10:([SC]*0.000762)-([SC]*0.000762)*10%1/10) km

** MILES *** 1 decimal
(([SC]*0.0004735)*10%1>0.5?([SC]*0.0004735)+0.1-([SC]*0.0004735)*10%1/10:([SC]*0.0004735)-([SC]*0.0004735)*10%1/10) mile

(numberFormat("#.#", ([SC]*0.0004735))) miles
(numberFormat("#.#", ([SC]*0.000762))) km
(numberFormat("###", ([SC]*0.048))) kcal
(numberFormat("##.#",([SC]/([SC_GOAL]/100))))%

3 Likes

I’m not quite sure on the round off why you have chosen >= 0.99
What if the number is >= 0.98?

As I wrote in another post, the round off gets you to the nearest whole number if you are greater than or equal to half way to the next whole number.

[tag] is the expression you are evaluating
([tag]*10%10/10>=0.5?[tag]+1-[tag]*10%10/10:[tag]-[tag]*10%10/10)

Upon further examination of how @GJL rewrote one of the formulas using %1 in the formula I can see how the tag expression could be reduced. I did find a further reduction on the formulas.

Let’s say the number is 36.5:

([tag]%1>=0.5?[tag]+1-[tag]%1:[tag]-[tag]%1)
0.5 >= 0.5 ? 36.5 + 1 - 0.5 : 36.5 - 0.5
0.5 >= 0.5 ? 37.5 - 0.5 : 36
0.5 >= 0.5 ? 37 : 36

If we want to round to the nearest 1 digit. Let’s say the number is 36.57:

([tag]*10%1>=0.5?[tag]+0.1-[tag]*10%1/10:[tag]-[tag]*10%1/10)
0.7 >= 0.5 ? 36.57 + 0.1 - 0.07 : 36.57 - 0.07
0.7 >= 0.5 ? 36.67 - 0.07 : 36.5
0.7 >= 0.5 ? 36.6 : 36.5

If I wanted to round to the nearest 2 digits. Let’s say the number is 36.576:

([tag]*100%1>=0.5?[tag]+0.01-[tag]*100%1/100:[tag]-[tag]*100%1/100)
0.6 >= 0.5 ? 36.576 + 0.01 - 0.006 : 36.576 - 0.006
0.6 >= 0.5 ? 36.586 - 0.006 : 36.57
0.6 >= 0.5 ? 36.58 : 36.57

To put them all together so you can see the pattern easier:

Round to nearest:
[tag] is the expression you are evaluating
([tag]%1>=0.5?[tag]+1-[tag]%1:[tag]-[tag]%1) whole number
([tag]*10%1>=0.5?[tag]+0.1-[tag]*10%1/10:[tag]-[tag]*10%1/10) 1 decimal
([tag]*100%1>=0.5?[tag]+0.01-[tag]*100%1/100:[tag]-[tag]*100%1/100) 2 decimals
([tag]*1000%1>=0.5?[tag]+0.001-[tag]*1000%1/1000:[tag]-[tag]*1000%1/1000) 3 decimals

Floor:
([tag] - [tag]%1)

Ceiling:
([tag]>[tag]-[tag]%1?[tag]+1-[tag]%1:[tag])

You mentioned Floor with tag, what is the tag for Floor?

to floor in this case means to make from decimal number a whole number by discarding the data behind decimal point. Not to count how high you climbed (WFS does not provide tag for this).

@Peter is correct. Someone had requested Floor/Ceiling algorithms, so I appended them to my post.

** KCAL ** Round off
(([SC]*0.048)%1>0.5?([SC]*0.048)+1-([SC]*0.044)%1:([SC]*0.048)-([SC]*0.048)%1) kcal

(numberFormat("###", ([SC]*0.048))) kcal

I can follow the above discussion, but I tried using round(num) as that would be easier. That does work in the emulator but not on my watch (Galaxy Watch 5 pro). I am using the following TAG expression:

(round([SC]/1335*100)/100) km (1,335 steps per km, two digits)

Am I doing something wrong or is this a bug?

Hello,

How is the Tag expressions for step count with number format 0 to 999, then 1.000 to …

Means between thousand and hundred digit a “.”.

Eg.
0
456
3.345
23.654

Thanks