0

I need a function that allows a string to be passed in that strips out everything before a decimal place. For example, 40.00% should be 40. However, it needs to be flexible enough to check if there are no decimals and still maintain the same result. For example, 70% becomes 70.

Help would be greatly appreciated!

Thanks in advance

3
Contributors
2
Replies
18
Views
4 Years
Discussion Span
Last Post by IIM
0

hai f_atencia

i dont have great knowledge at coding side but i want to give a way to solution to your requirement.

please start as follows

steps:

  1. first replace '%'charecter with empty charecter in the given number string by using replace('%','');

  2. then find '.' symbol in the given number string by using split(".") or using indexOf('.') javascript functions
    (note: you didn't mention what we have to do for the number 45.67% having this kind of format in the above post)

if you are ready to use split(delimiter_charecter) funtion

then display the first part after the split(delimiter_charecter) function is applied to the string what we got in the first step

this is not the exact solution for your requirement but it gives the output for your requirement

try to start coding as described above

if you have any doubts in my clarification

let me know

any comments are appreciated

happy coding

Edited by radhakrishna.p: clarifyning the solution to the problem

0

@radha:-
Better solution will be:-

Steps

  • first replace '%'charecter with empty charecter in the given number string by using replace('%','');
  • convert then string to decimal and then typecast decimal to integer.

    function convertToInteger(c)
    {
    c= c.replace('%','');
    alert(Math.floor(parseInt(c)));
    }

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.