how to remove decimal from the string field in the server side script

RudhraKAM
Tera Guru

I have this code in the server side , it is giving the result as 44.0 I want only 44 

 current.variables.sds_price = parseInt(current.cmdb_ci.market_value)/1024;

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

Please check sample examples from below link , give a try . let me know if it's still not working. 

 

https://stackoverflow.com/questions/7641818/how-can-i-remove-the-decimal-part-from-javascript-number

View solution in original post

12 REPLIES 12

Allen Andreas
Administrator
Administrator

Hi,

You can use:

var priceCalc = parseInt(current.cmdb_ci.market_value)/1024;
var newNum = (""+priceCalc).split('.')[0];
current.variables.sds_price = Number(newNum);

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

thanks Allen , still not working 

Hi,

Please provide a bit more information as to how it's not working, can you share what you've done. I tested this myself prior to posting it and know it works.

For the other suggestion below, by the other poster, with using Math.round, that is also a viable option...if...you want to actually round the integer. If you're simply wanting to chop off the decimal and any digit thereafter, with no rounding, then what I've mentioned above will do that.

Up to you 🙂

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Thanks Allen , 

so what I am doing is getting the value for a CI field which  is of type integer , for some reason it is populating as 44.0 while setting it to the variable , I tried your code which will act on a variable which will present in Task  , when I check in Background script that is displaying without decimal , but via workflow I am getting that decimal value.