# .rounded()

{% tabs %}
{% tab title="💈範例" %}
```swift
// ⭐️ .toNearestOrAwayFromZero (就是四捨五入)
(5.2).rounded()         //  5.0
(5.5).rounded()         //  6.0
(-5.2).rounded()        // -5.0
(-5.5).rounded()        // -6.0

let x = 6.5

// use rounding rules
x.rounded(.toNearestOrAwayFromZero)    // round: 7.0
x.rounded(.towardZero))                // trunc: 6.0 ⭐️ 
x.rounded(.up)                         // ceil : 7.0 ⭐️ 
x.rounded(.down)                       // floor: 6.0 ⭐️ 

// ⭐️ Int
Int(3.25)        //  3
Int(3.7)         //  3
Int(-3.3)        // -3
Int(-3.7)        // -3
```
{% endtab %}

{% tab title="📘 手冊" %}
* [Swift](https://developer.apple.com/documentation/swift) ⟩&#x20;
  * [Double](https://developer.apple.com/documentation/swift/double) ⟩&#x20;
    * [.rounded()](https://developer.apple.com/documentation/swift/double/2886778-rounded) - use <mark style="color:red;">**.toNearestOrAwayFromZero**</mark> rounding rule.
    * [.rounded(\_:)](https://developer.apple.com/documentation/swift/double/2886735-rounded) - use **other** rounding rules.
    * [.round()](https://developer.apple.com/documentation/swift/double/2884722-round), [.round(\_:)](https://developer.apple.com/documentation/swift/double/2298718-round) - round **in place**.
  * [FloatingPoint](https://developer.apple.com/documentation/swift/floatingpoint) ⟩&#x20;
    * [.round(\_:)](https://developer.apple.com/documentation/swift/floatingpoint/2298113-round)
  * [Int](https://developer.apple.com/documentation/swift/int) ⟩&#x20;
    * init(\_:)
{% endtab %}
{% endtabs %}
