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

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

@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)));
    }

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.