10-11-2018 18:51
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-11-2018 18:51
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hopefully an easy one...
How do I assign a percentage value to the var.x value? I can assign it a number (pixel):
myVar.x = 100;
I have yet to crack how to assign a percentage like I do in the .css. Both of these fail:
myVar.x = 40%;
myVar.x = "40%";
What am I missing here?
Thanks.
Answered! Go to the Best Answer.

Accepted Solutions
10-12-2018 04:20
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


10-12-2018 04:20
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Sorry, the percentage values aren't currently supported, but you can calculate the pixel value from the device screen dimensions.
import { me as device } from "device";
if (!device.screen) device.screen = { width: 348, height: 250 };
let percent = 40;
let pixels = percent / 100 * device.screen.width;
myVar.x = pixels;

10-12-2018 04:20
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


10-12-2018 04:20
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Sorry, the percentage values aren't currently supported, but you can calculate the pixel value from the device screen dimensions.
import { me as device } from "device";
if (!device.screen) device.screen = { width: 348, height: 250 };
let percent = 40;
let pixels = percent / 100 * device.screen.width;
myVar.x = pixels;

10-13-2018 14:03
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-13-2018 14:03
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thanks JohnFitbit. I am doing something similar to your solution, but I was hoping there might be a cleaner/simpler way of doing it.
Jeff

