简体   繁体   中英

How to convert metres to centimetres in Monkey C?

Serious newbie question, but I can't seem to find the answer anywhere!

I'm trying to convert my height from centimetres to metres in an application for my Garmin device. This is written in Monkey C (very similar to Java and C++ from what I understand).

Here's how I'm currently doing it:

var height = angus.height;
var heightCM = height.format("%0.2f");

My height is 175, and so as you might expect, this gives me a result of 175.00

I can't seem to find any resource that tells me how to essentially move a decimal to the left. Any help would be really appreciated.

Here's the documentation on formatting in Monkey C: https://developer.garmin.com/downloads/connect-iq/monkey-c/doc/Toybox/Lang/Number.html#format-instance_method

Any explanation on formatting numbers would be great. I'm also attempting to truncate a number, so from 1234567 to 1234, for example. So any information on that would also be great.

Thanks in advance!

你应该使用:

var height = angus.height / 100.0; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM