-6

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!

dda
  • 6,030
  • 2
  • 25
  • 34
Tube Oid
  • 1
  • 1
  • 1
    Even if you're programming a language *similar* to some other languages, you should not really add those other unrelated language tags. – Some programmer dude Feb 05 '17 at 11:23
  • _I can't seem to find any resource that tells my how to essentially move a decimal to the left!_ ever heard of division? – tkausl Feb 05 '17 at 11:24
  • 4
    As for your problem, have you ever heard about *division*? Think back to basic school math: What happens when you divide a number by `10`? By `100`? By `1000`? – Some programmer dude Feb 05 '17 at 11:24
  • Hey, yeah I tried dividing it, but then I still get a strange result, for example: var height = angus.height / 100; var heightCM = height.format("%0.2f"); That gives me: 1.00 Am I using the wrong formatting? – Tube Oid Feb 05 '17 at 16:42
  • 2
    The title should be about converting centimetres to metres instead of the other way around. – Adam Evans Apr 16 '17 at 01:29

1 Answers1

8

You should use:

var height = angus.height / 100.0;