---
title: "avrundningsfunktion?"
type: "forum-thread"
url: "https://www.webforum.nu/amne/javascript/87906-avrundningsfunktion"
topic: "JavaScript"
topic_url: "https://www.webforum.nu/amne/javascript"
author: "Prästen"
published: "2003-10-07T15:23:24.000Z"
updated: "2003-10-07T18:51:06.000Z"
replies: 5
views: 305
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/javascript/87906-avrundningsfunktion"
---

# avrundningsfunktion?

## #1 — Prästen, 2003-10-07T15:23Z

Hello jag undrar över ett par saker.

1\. Finns det någon avrundningsfunktion i javascript som avrundar ett värde 

2\. Vilken variabeltyp kan innehålla decimaler i Java-Script?

Permalänk: https://www.webforum.nu/p/87906

## #2 — dectgap, 2003-10-07T15:37Z

1\. *Math.round()* avrundar tal:
<http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/math.html#1197725>

2\. Flyttal kan innehålla decimaler, men du behöver inte ange att en variabel ska vara av typen flyttal:

```
var approxPI = 3.1415;
```

Permalänk: https://www.webforum.nu/p/1179328

## #3 — Prästen, 2003-10-07T15:44Z

Tack tack, Math.Round hjälpte utmärkt :)

Permalänk: https://www.webforum.nu/p/1179337

## #4 — Cheguelin, 2003-10-07T16:25Z

Math.ceil om du vill avrunda uppåt, Math.floor om du vill avrunda neråt.

Permalänk: https://www.webforum.nu/p/1179379

## #5 — Prästen, 2003-10-07T17:22Z

aha, men round då?, tar några exempel.

avrundar den såhär?

1\.51=2
1\.49=1

??

Permalänk: https://www.webforum.nu/p/1179414

## #6 — dectgap, 2003-10-07T18:51Z

Citat från länken jag gav dig:

> **Description**
> If the fractional portion of number is .5 or greater, the argument is rounded to the next higher integer. If the fractional portion of number is less than .5, the argument is rounded to the next lower integer.
> 
> Because round is a static method of Math, you always use it as Math.round(), rather than as a method of a Math object you created.
> 
> **Examples**
> 
> //Returns the value 20
> x=Math.round(20.49)
> 
> //Returns the value 21
> x=Math.round(20.5)
> 
> //Returns the value -20
> x=Math.round(-20.5)
> 
> //Returns the value -21
> x=Math.round(-20.51)

Permalänk: https://www.webforum.nu/p/1179462

---

Tråden på webben: https://www.webforum.nu/amne/javascript/87906-avrundningsfunktion
