Share vb.net math.round

thelam237

New member
** chức năng vb.net Math.Round () **

Hàm ** math.round () ** trong vb.net làm tròn một số cho một số vị trí thập phân được chỉ định.Cú pháp của hàm Math.Round () như sau:

`` `
Math.Round (số, chữ số)
`` `

*** Số ** là số được làm tròn.
*** Digits ** là số lượng vị trí thập phân để làm tròn đến.

Hàm Math.Round () trả về một số điểm nổi có độ chính xác kép được làm tròn đến số vị trí thập phân được chỉ định.

Ví dụ: mã sau làm tròn số 12.3456 đến 2 số thập phân:

`` `
Số Dim dưới dạng gấp đôi = 12.3456
Dim RoundedNumber dưới dạng double = math.Round (số, 2)

Console.WriteLine (RoundedNumber)
`` `

Mã này sẽ xuất ra như sau:

`` `
12,35
`` `

Bạn cũng có thể sử dụng hàm Math.Round () để làm tròn một số vào số nguyên gần nhất.Để thực hiện việc này, chỉ cần đặt tham số ** chữ số ** thành 0.

Ví dụ: mã sau làm tròn số 12.3456 cho số nguyên gần nhất:

`` `
Số Dim dưới dạng gấp đôi = 12.3456
Dim RoundedNumber dưới dạng double = math.Round (số, 0)

Console.WriteLine (RoundedNumber)
`` `

Mã này sẽ xuất ra như sau:

`` `
12
`` `

** Hashtags: **

* #vb.net
* #Toán học
* #Rounding
* #Số điểm nổi
* #Integers
=======================================
**VB.NET Math.Round() Function**

The **Math.Round()** function in VB.NET rounds a number to a specified number of decimal places. The syntax of the Math.Round() function is as follows:

```
Math.Round(number, digits)
```

* **number** is the number to be rounded.
* **digits** is the number of decimal places to round to.

The Math.Round() function returns a double-precision floating-point number that is rounded to the specified number of decimal places.

For example, the following code rounds the number 12.3456 to 2 decimal places:

```
Dim number As Double = 12.3456
Dim roundedNumber As Double = Math.Round(number, 2)

Console.WriteLine(roundedNumber)
```

This code will output the following:

```
12.35
```

You can also use the Math.Round() function to round a number to the nearest integer. To do this, simply set the **digits** parameter to 0.

For example, the following code rounds the number 12.3456 to the nearest integer:

```
Dim number As Double = 12.3456
Dim roundedNumber As Double = Math.Round(number, 0)

Console.WriteLine(roundedNumber)
```

This code will output the following:

```
12
```

**Hashtags:**

* #vb.net
* #Math
* #Rounding
* #floating-point numbers
* #Integers
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top