how to make round input boxes by richarduie
The content (value) returned by prompt() is of the String type. You're using parseInt() on the value, and it's working exactly correctly, i.e., it's reading numeral String up to the first non-numeral character and converting it to an Integer. What you should be using for decimal input Strings is parseFloat() NOT parseInt().
For fractions of the form {m/n},recognize that the {/} is an operator (a non-numeral character), and parse*() functions aren't appropriate. You need to evaluate the expression, using the eval() function.
how to make round input boxes by P.S.P.
I have several questions on avoiding JavaScript rounded calculations on information (integers/numbers) from prompt boxes, and then with entering fractions in prompt boxes where prompt boxes always ignores the denominator of fractions that's put in. (i.e. if I put in 2/5 in a prompt box then convert it to integer, javascript will count that as 2, which is nowhere near 2/5!)
So, I'm still working around making some calculators with JavaScript, I got the basics down to make these calculators work efficiently. On one of my calculators, it is the slope calculators:
For example, if I want to calculate the slope of a line, my calculator would give me decimals as the result, it's ok, but if I want to just get the regular fractions returned instead of decimals how can I do that with JavaScript?
Also, using the prompt box to collect information from user, then converting that information to integers using parse.Int(), it always automatically rounded fraction to the nearest ones, which I don't want either.
For example, if I put in 2.4 in a prompt box, it will return as 2, which is bad for full calculation, how can I make prompt boxes return integer information as what it is without rounding it?
Then, even worse if I put in fractions in prompt box, it always ignores then denominator of it. For example, if I have a fraction of 10/0 JavaScript thinks of it as just 10, when it should be undefined! Same with regular denominator, if I put in 10/2 Javascript will still think of it as 10.
All of these is user input using the prompt boxes, which later I convert to integers with parse.Int()
Help would be greatly appreciated for fixing all of these problems that I don't want. Thanks!
Español
|
English |
Português
|
Русский
|
Contact us All opinions expressed here belong to the authors and do not necessarily reflect the opinions of Slogbox.com