Khác biệt giữa bản sửa đổi của “Trợ giúp:Tính toán”

Nội dung được xóa Nội dung được thêm vào
nKhông có tóm lược sửa đổi
Dòng 7:
 
== #expr ==
 
Hàm này định giá trị của một biểu thức toán học và trả về giá trị đã tính được.
 
:<tt><nowiki>{{#expr:</nowiki> ''biểu thức'' <nowiki>}}</nowiki></tt>
 
Các toán tử hợp lệ được liệt kê ở phía dưới theo trật tự quyền ưu tiên. Xem thông tin chi tiết về hàm số của mỗi toán tử tại {{mediawiki|m:Help:Calculation|Help:Calculation}}. Độ chính xác và định dạng của kết quả trả về sẽ thay đổi tùy thuộc vào hệ điều hành của máy chủ (server) chạy wiki, và tùy thuộc vào định dạng số trên ngôn ngữ trang.
{| {{prettytable|style=float:right; width:30%; margin-left:1em;align:right;}}
|-
!{{hl1}} | Loại
!{{hl1}} | Toán tử
|-
|{{hl2}} | Nhóm (các dấu ngoặc)
| style="word-spacing:0.5em; font-family:monospace; font-weight:bold;" | ( )
|-
|{{hl2}} | Số
| style="word-spacing:0.5em;" | <tt>'''1234.5'''</tt> <tt>'''2.4E5'''</tt> <tt>'''e'''</tt>&nbsp;(2.718) <tt>'''pi'''</tt>&nbsp;(3.142)
|-
|{{hl2}} rowspan="3" | Logic
| style="word-spacing:0.5em; font-family:monospace; font-weight:bold;" | or
|-
| style="word-spacing:0.5em; font-family:monospace; font-weight:bold;" | and
|-
| style="word-spacing:0.5em; font-family:monospace; font-weight:bold;" | = != <> > < <= >=
|-
|{{hl2}} | Làm tròn
| style="word-spacing:0.5em; font-family:monospace; font-weight:bold;" | round
|-
|{{hl2}} rowspan="3" | Toán tử hai ngôi
| style="word-spacing:0.5em; font-family:monospace; font-weight:bold;" | + - mod
|-
| style="word-spacing:0.5em; font-family:monospace; font-weight:bold;" | * / div
|-
| <tt>'''^'''</tt>
|-
|{{hl2}} rowspan="2" | Toán tử một ngôi
| style="word-spacing:0.5em; font-family:monospace; font-weight:bold;" | not ceil trunc floor abs ln sin cos tan acos asin atan
|-
| style="word-spacing:0.5em; font-family:monospace; font-weight:bold;" | e + -
|}
When evaluating using {{mediawiki|w:boolean algebra (logic)|boolean algebra}}, zero evaluates to <tt>false</tt> and any nonzero value, positive or negative, evaluates to <tt>true</tt>:
 
:<tt><nowiki>{{#expr: 1 and -1 }}</nowiki></tt> &rarr; '''{{#expr: 1 and -1 }}'''
:<tt><nowiki>{{#expr: 1 and 0 }}</nowiki></tt> &rarr; '''{{#expr: 1 and 0 }}'''
 
An empty input expression returns an empty string. Invalid expressions return one of several error messages, which can be caught using the <tt>[[##iferror|#iferror]]</tt> function:
 
:<tt><nowiki>{{#expr: }}</nowiki></tt> &rarr; ''' {{#expr: }}'''
:<tt><nowiki>{{#expr: 1+ }}</nowiki></tt> &rarr; '''{{#expr: 1+ }}'''
:<tt><nowiki>{{#expr: 1 foo 2 }}</nowiki></tt> &rarr; '''{{#expr: 1 foo 2 }}'''
 
{{warning|Some expressions may invoke floating-point errors when used with very large or very small numbers:<br />
<tt><nowiki>{{#expr: 20060618093259 mod 10000}}</nowiki></tt> &rarr; '''{{#expr: 20060618093259 mod 10000}}''' in most cases, but may occasionally give '''-6357'''. This varies with the specification and configuration of the server running the wiki. See {{bugzilla|6356}}.
}}
 
Hàm <code>#expr</code> tính các biểu thức [[toán học]]. Các phép tính (theo thứ tự tính) là: