Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

Trim £ sign from array

Hi,
I have the following code to save some labels to array, all is working fine, here is a sample of saved array

The problem Im having is on another screen I need to total all the TotalPrices in all saved arrays

The code I have to calculate works fine except for the £ sign

So my question is, do I need to trim the £ sign when saving the array or can it be trimmed on the callculation event

Thanks

[{"Pizza":"Al Fungi","Size":"12 Inch Stuffed Crust","Toppings":"Pepperoni,Salami,Cheese","TotalPrice":"£9.90"}]

code$grid = $(this).closest("[name=chickengrid1]");
save({'Pizza':($grid.find("[name=pizzalabel1]").text()).replace(/(\r\n|\n|\r)/gm,"").replace(/\s\s/, '').replace(/\s\s$/, ''),
'Size':$grid.find("[name=orderlabel1]").text(),
//'Base':$grid.find("[name=thin_deeptoggle]").val(),
'Toppings':(($grid.find(".alfungi_toppinggridcell1").text()).replace(/(\r\n|\n|\r)/gm,"")).replace(/\s\s/, '').replace(/\s\s$/, '').split(/[ ,]+/).join(','),
'TotalPrice':$grid.find("[name=totalpricelabel1]").text()},
"mainorderArray");/code

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

Trim £ sign from array

Sorry I forgot the code to do the calculation, here it is below
As you can see I have a lot of arrays, If this code could be altered to account for the £ sign would be easier that having to add trim when saving

Thanks in advance

codevar price;
try {
price = JSON.parse(localStorage.getItem("mainorderArray"));
if ({}.toString.call(price) !== "[object Array]") {
price = [];
}
} catch ( e ) {
price = [];
}
var extrasprice;
try {
extrasprice = JSON.parse(localStorage.getItem("livesundriesorderArray"));
if ({}.toString.call(extrasprice) !== "[object Array]") {
extrasprice = [];
}
} catch ( e ) {
extrasprice = [];
}
var kebabpricelabel;
try {
kebabpricelabel = JSON.parse(localStorage.getItem("kebabArray"));
if ({}.toString.call(kebabpricelabel) !== "[object Array]") {
kebabpricelabel = [];
}
} catch ( e ) {
kebabpricelabel = [];
}

var grillpricelabel;
try {
grillpricelabel = JSON.parse(localStorage.getItem("grillArray"));
if ({}.toString.call(grillpricelabel) !== "[object Array]") {
grillpricelabel = [];
}
} catch ( e ) {
grillpricelabel = [];
}

var TotalPrice;
try {
TotalPrice = JSON.parse(localStorage.getItem("mealdeal1Array"));
if ({}.toString.call(TotalPrice) !== "[object Array]") {
TotalPrice = [];
}
} catch ( e ) {
TotalPrice = [];
}

var deal2pricelabel;
try {
deal2pricelabel = JSON.parse(localStorage.getItem("deal2Array"));
if ({}.toString.call(deal2pricelabel) !== "[object Array]") {
deal2pricelabel = [];
}
} catch ( e ) {
deal2pricelabel = [];
}

var deal4pricelabel;
try {
deal4pricelabel = JSON.parse(localStorage.getItem("deal4Array"));
if ({}.toString.call(deal4pricelabel) !== "[object Array]") {
deal4pricelabel = [];
}
} catch ( e ) {
deal4pricelabel = [];
}

var kidsheaderpricelabel;
try {
kidsheaderpricelabel = JSON.parse(localStorage.getItem("kidsArray"));
if ({}.toString.call(kidsheaderpricelabel) !== "[object Array]") {
kidsheaderpricelabel = [];
}
} catch ( e ) {
kidsheaderpricelabel = [];
}

var burgerheaderpricelabel;
try {
burgerheaderpricelabel = JSON.parse(localStorage.getItem("burgerArray"));
if ({}.toString.call(burgerheaderpricelabel) !== "[object Array]") {
burgerheaderpricelabel = [];
}
} catch ( e ) {
burgerheaderpricelabel = [];
}

var wrappricelabel;
try {
wrappricelabel = JSON.parse(localStorage.getItem("wrapArray"));
if ({}.toString.call(wrappricelabel) !== "[object Array]") {
wrappricelabel = [];
}
} catch ( e ) {
wrappricelabel = [];
}

var calzoneheaderpricelabel;
try {
calzoneheaderpricelabel = JSON.parse(localStorage.getItem("calzoneArray"));
if ({}.toString.call(calzoneheaderpricelabel) !== "[object Array]") {
calzoneheaderpricelabel = [];
}
} catch ( e ) {
calzoneheaderpricelabel = [];
}

var garlicheaderpricelabel;
try {
garlicheaderpricelabel = JSON.parse(localStorage.getItem("garlicArray"));
if ({}.toString.call(garlicheaderpricelabel) !== "[object Array]") {
garlicheaderpricelabel = [];
}
} catch ( e ) {
garlicheaderpricelabel = [];
}

var totalprice = 0;
for (i = 0; i < price&#46;length; i++){
totalprice += +price["Price"];
};
for (i = 0; i < extrasprice&#46;length; i++){
totalprice += +extrasprice["Price"];
};

for (i = 0; i < grillpricelabel&#46;length; i++){
totalprice += +grillpricelabel["Price"];
};

for (i = 0; i < kebabpricelabel&#46;length; i++){
totalprice += +kebabpricelabel["Price"];
}

for (i = 0; i < TotalPrice&#46;length; i++){
totalprice += +TotalPrice["Price"];
};

for (i = 0; i < deal2pricelabel&#46;length; i++){
totalprice += +deal2pricelabel["Price"];
};

for (i = 0; i < deal4pricelabel&#46;length; i++){
totalprice += +deal4pricelabel["Price"];
};

for (i = 0; i < kidsheaderpricelabel&#46;length; i++){
totalprice += +kidsheaderpricelabel["Price"];
};

for (i = 0; i < burgerheaderpricelabel&#46;length; i++){
totalprice += +burgerheaderpricelabel["Price"];
};

for (i = 0; i < wrappricelabel&#46;length; i++){
totalprice += +wrappricelabel["Price"];
};

for (i = 0; i < calzoneheaderpricelabel&#46;length; i++){
totalprice += +calzoneheaderpricelabel[i]["Price"];
};

for (i = 0; i < garlicheaderpricelabel&#46;length; i++){
totalprice += +garlicheaderpricelabel[i]["Price"];
};

localStorage&#46;setItem("totalprice", totalprice)/code

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

Trim £ sign from array

any chance of some guidance here.

Thanks

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Trim £ sign from array

Hello Michael,

Unfortunately custom JS code is outside the scope of standard Appery.io platform support (https://devcenter.appery.io/support-p...). You may consider purchasing Advisory Pack to get more in-depth help on this question. Here is more information about it: http://appery.io/services/#Advisory_Pack

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

Trim £ sign from array

I dont think you read the question

So my question is, do I need to trim the £ sign when saving the array or can it be trimmed on the callculation event

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

Trim £ sign from array

Incase anyone else has a similar question,
symbol can be trimed out on the calculation event
see code above and addition below

for (i = 0; i < kebabpricelabel.length; i++){
totalprice += +(kebabpricelabel["Price"].replace(/(\r\n|\n|\r)/gm,"").trim().slice(1));
}

support are not allowed to to tell you

Return to “Issues”