# round up numbers

Page 1 of 1

## 4 Replies - 976 Views - Last Post: 25 September 2012 - 12:50 PM

### #1 jaynajay

Reputation: 0
• Posts: 26
• Joined: 17-September 12

# round up numbers

Posted 25 September 2012 - 10:55 AM

I am trying to round up the results for this block of JS code. I tried Math.round, and it did not work, or may be I don't know where and how to use this. Can you please advise me on how to round up the result for "hoursOfVacationPerMinute".
Currently if I run the code, I get 0.0009132420091324201 for hoursOfVacationPerMinute

```
hoursOfVacationPerMinute = totalVacationHours / dividend;
document.write("Hours of vacation per Minute:     " +hoursOfVacationPerMinute+ "</br>");

```

Is This A Good Question/Topic? 0

## Replies To: round up numbers

### #2 Martyr2

• Programming Theoretician

Reputation: 4917
• Posts: 13,303
• Joined: 18-April 07

## Re: round up numbers

Posted 25 September 2012 - 11:15 AM

Math.round() works to round up/down to nearest integer (aka whole number). You can use the toFixed() method to specify rounding to a decimal place...

```(0.0009132420091324201).toFixed(3)

```

This would give you .001 or your number rounded to the thousandths place. Now keep in mind that Javascript stores numbers as floating point so some numbers can't be represented EXACTLY. If you are using this for extremely precise number calculations, you will need something else. However, this method can serve you in getting some approximations.

This post has been edited by Martyr2: 25 September 2012 - 11:22 AM

### #3 jaynajay

Reputation: 0
• Posts: 26
• Joined: 17-September 12

## Re: round up numbers

Posted 25 September 2012 - 11:45 AM

Is this the right way to assign it. if it is, the output on the screen is blank this time.

```document.write("Hours of vacation per Minute:     "(hoursOfVacationPerMinute5).toFixed(2));

```

### #4 Dormilich

• 痛覚残留

Reputation: 3984
• Posts: 12,279
• Joined: 08-June 10

## Re: round up numbers

Posted 25 September 2012 - 12:20 PM

there is the concatenation missing.

### #5 jaynajay

Reputation: 0
• Posts: 26
• Joined: 17-September 12

## Re: round up numbers

Posted 25 September 2012 - 12:50 PM

Thanks again. It worked!!!