I am trying to convert incoming values as below
Example: Input: 00000016B Output: 000000162
Whenever I see a "Character" from below table at the last character of a incoming input value, I need to convert as per below table.
1.My Input "00000016B" changed to "000000162" as B should be replaced by "+2", so the input is a positive number and last character should be a "2"
2.My Input "00000016K" changed to "-000000162" as K should be replaced by "-2", so the input is a negative number and last character should be a "2"
| Character | Value |
| -------- | -------|
| { | +0 |
| A | +1 |
| B | +2 |
| C | +3 |
| D | +4 |
| E | +5 |
| F | +6 |
| G | +7 |
| H | +8 |
| I | +9 |
| } | -0 |
| J | -1 |
| K | -2 |
| L | -3 |
| M | -4 |
| N | -5 |
| O | -6 |
| P | -7 |
| Q | -8 |
| R | -9 |
I tried below code
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
function replaceAll(QtyProcess, map){
for(key in map){
QtyProcess = QtyProcess.replaceAll(key, map[key]);
}
return QtyProcess;
}
var QtyProcess = QtyTireDate.substr(8,9);
var map = {
'{': '+0',
'A': '+1',
'B': '+2',
'C': '+3',
'D': '+4',
'E': '+5',
'F': '+6',
'G': '+7',
'H': '+8',
'I': '+9',
'}': '-0',
'J': '-1',
'K': '-2',
'L': '-3',
'M': '-4',
'N': '-5',
'O': '-6',
'P': '-7',
'Q': '-8',
'R': '-9'
};
var lastChar= replaceAll(QtyProcess, map);
var lastNum = QtyProcess.substr (0,QtyProcess.length -1);
if (lastChar.substr(0,1) == "-") {
var QTYFinal = '-'+lastNum.concat(lastChar.substr(1,1));
} else {
var QTYFinal = lastNum.concat(lastChar.substr(1,1));
}
It always gives me zero at the end