|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
hi,
i was having this problem on how to round a number into 2 decimal places. I have read some of the tutorials but with my case I don't know how to do it. i hope someon could help with this one. all the 3 input box should have 2 decimal places only. thank you in advance. PHP Code:
|
|
#2
|
|||
|
|||
|
Code:
function update1 ()
{
var input = document.getElementById ("work_hours").value;
var num = new Number (parseFloat (input));
var fixed = num.toFixed (2);
}
|
|
#3
|
||||
|
||||
|
alternatively, you could use:
round($variable, 2) |
|
#4
|
|||
|
|||
|
Quote:
You sure this works? The Core JS Reference doesn't mention anything about a round () function that accepts two parameters? The only round () function I could find was in the Math class and that accepts one parameter and rounds it to the nearest integer (i.e. no decimal places) |
|
#5
|
||||
|
||||
|
round() is a PHP-function. You asked your question in a PHP-forum, so don't be surprised if you get a PHP-answer.
I suggest you use the PHP-function. JS can be turned off by users.
__________________
Work to live, don't live to work |
|
#6
|
|||
|
|||
|
Quote:
D'oh! I took a look at the original code and thought that the person asking wanted a JS solution. Yeah, I'd actually push the PHP solution since users can turn off JS. Boy, is my face red ![]() |
|
#7
|
|||
|
|||
|
Actually I did this
Quote:
the form is ok now it already rounds off the number into 2 decimal places, however, my database stores the number I input with 3 decimal places. ![]() |
|
#8
|
|||
|
|||
|
thanks for all your responses.
|
|
#9
|
||||
|
||||
|
moved to JavaScript Development should have been moved before
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > round into 2 decimal places |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|