Skip to content

[Locale] How to get short distance units? #7830

Closed Answered by gfwilliams
RKBoss6 asked this question in Bangle.js
Discussion options

You must be logged in to vote

You can use:

// Distance/Length (in meters) to formatted String
>require("locale").distance(150)
="150m"

// Automatic unit selection for larger distances
>require("locale").distance(15000)
="15km"

The units will change depending on the magnitude of the value you pass in - or are you saying you want to always have the small units, regardless of the magnitude?

The code that handles distance is at https://github.com/espruino/BangleApps/blob/master/apps/locale/locale.html#L208, and I guess it might be possible to change it to force it, but we'd also have to change the version in the Espruino firmware.

We have date_utils to provide some extra features on top of locale (https://github.com/esp…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@RKBoss6
Comment options

@RKBoss6
Comment options

Answer selected by RKBoss6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants