Simple Math Function Help in Javascript


Simple Math Function Help in Javascript





This is the webpage --> http://dawasco.unaux.com



I wanted to make a simple math function whereby:



The value x is taken and then added with 0.01 or 1% of x



Basically : x + (0.01x)



Then 1000 is added to the result value i.e.



In this Case : 1.01x +1000



Finally the result is rounded UP to the nearest hundreds



So in this case if we take x=1 then the total ;1001.01 will be rounded up to 1100



1.
Lets say the input value is: 94,000



1% of 94,000 is 940 so:



94,000 + 940 = 94940






94940 + 1000 = 95940




4.
the total i.e. 95940 is rounded Up to the nearest hundreds



95,940 = 96,000



My questions are:
1. How do i set a parameter to round off the values in 100s. math.ceil() here
2. How do i connect the input box and the javascript file
3. How do i display the output in the output box?
4. I tried using variables but failed so basically i need a solution


math.ceil()





If you have been working on this, share your Minimal, Complete, and Verifiable example and explain the problem you are facing in your implementation.
– Esko
Jun 29 at 10:25





What have you tried so far? Note that the problem, as posted, has a (maybe unexpected) difficulty and could require arbitrary precision floats or similar.
– ASDFGerte
Jun 29 at 10:26





Well i tried using the math.ceil() for rounding up the number i didnt know how to set a parameter which only rounded in 100s
– Ally
Jun 29 at 11:21


math.ceil()





“i didnt know how to” - newsflash: This is the point were you are supposed to do some basic research! Typing something trivial such as “javascript round number to next 100” into Google would have led you to stackoverflow.com/q/19621455/1427878 in no time.
– CBroe
Jun 29 at 11:36






@CBroe Hey Man!. I apologize if I annoyed or made you angry. I am still a learner and have a long way to go. I appreciate your help and thank you ! Have a Nice Day !
– Ally
Jun 29 at 12:05




1 Answer
1



It should do the trick if you always want to round to the nearest hundred.


function computation(number) {
let newNumber = number + (1/100 * number) + 1000;
let roundedNumber = Math.round(newNumber/100)*100;
return roundedNumber;
}





This is great! But how do I link the <input> and the <output> Tag?
– Ally
Jun 29 at 11:54


<input>


<output>





Aha you should read the javascript documentation, I can't give you the exact answer, it depend on your HTML and Javascript code :)
– Simon Bruneaud
Jun 29 at 12:24





Nice Simon and thanks once more!
– Ally
Jun 29 at 12:28






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Export result set on Dbeaver to CSV

Opening a url is failing in Swift