- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2021 01:26 AM
Hi All,
Getting below error, Please help.
12.92 - working fine
12.349 - working fine, rounded off to 12.35
12 - not working, getting below error.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2021 02:10 AM
Hello,
Your issue is with this line:
var finalcostStr1len = finalcost.split('.')[1].length;
Since 12 has no decimal point you cannot split on the '.' and get attempt to get the second index of an array that does not exist.
You might want to check that a decimal point exists before attempting a split on it.
So something like:
// check that decimal exists first
if(finalcost.indexOf('.') != -1){
// do something..
}
Someone else I'm sure will have a nicer solution, but this at least should highlight the issue with your existing code 🙂
Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2021 02:07 AM
Hello,
You add logic to check if value cost is float or integer
if it is float then only run your logic inside if block
Please refer below code
n = 12 // n can be refer to as your Finalcost variable
if(n === +n && n !== (n|0)){
// your logic will run only when number entered is float
gs.log("Float");
}
Please let me know if you need any other help
And correct me if I am wrongly understand your question
Thanks ,
Valmik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2021 02:10 AM
Hello,
Your issue is with this line:
var finalcostStr1len = finalcost.split('.')[1].length;
Since 12 has no decimal point you cannot split on the '.' and get attempt to get the second index of an array that does not exist.
You might want to check that a decimal point exists before attempting a split on it.
So something like:
// check that decimal exists first
if(finalcost.indexOf('.') != -1){
// do something..
}
Someone else I'm sure will have a nicer solution, but this at least should highlight the issue with your existing code 🙂
Geoff