Page 1 of 1

Numberformat

Posted: 23 Apr 2015 23:31
by Nocturno7
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

Re: Numberformat

Posted: 24 Apr 2015 10:45
by Martin
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

Re: Numberformat

Posted: 24 Apr 2015 20:09
by Nocturno7
Ooooo it is working.
Thank you
Have a nice evening