Numberformat

Post your feature requets for new triggers, conditions, actions and other improvements.

Moderator: Martin

Locked
Nocturno7
Posts: 2
Joined: 23 Apr 2015 22:50

Numberformat

Post by Nocturno7 » 23 Apr 2015 23:31

HI.
I have a problem.
For example, I have a number= 838 730 .It is a counter for my car in Km
Number is from another app that calculates Km using GPS and show in this number with space.
I have this number in variable.
I want to show in status bar.
But i need this number without space between the number.
How to change the number?
Script: a = 838 730 - 838 000
730 it is Km morning
000 it is Km evening
This is not right because the automagic not know that it is an integer.
Script: a = 838730 - 838000 Is this correct, and the result is correct but i need number without space...i do not a have it :-(
LOG AUTOMAGIC:can not apply operation - to values '838 730' and '838 000'
Thx
Have a nice evening

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Numberformat

Post by Martin » 24 Apr 2015 10:45

Hi,

You have to remove the space before the substraction can be done.
In a script you could replace the whitespace with an empty string:

Code: Select all

a="838 730";
b="838 000";
result = replace(a, " ", "") - replace(b, " ", "");
or using Regex:

Code: Select all

a="838 730";
b="838 000";
result = replaceAll(a, "\\s", "") - replaceAll(b, "\\s", "");
The second script using regex is a bit more robust since it will remove all type of whitespaces like spaces, tabs etc.

Regards,
Martin

Nocturno7
Posts: 2
Joined: 23 Apr 2015 22:50

Re: Numberformat

Post by Nocturno7 » 24 Apr 2015 20:09

Ooooo it is working.
Thank you
Have a nice evening

Locked