Number notation¶
There are many different ways of writing a number, depending on culture and context.
Numbas can interpret and display numbers in several styles.
Styles of notation¶
Numbas supports the following styles of notation. The entry in the “Code” column is the string you should use to identify the style in JME or JavaScript code.
Style |
Code |
Description |
Example |
---|---|---|---|
English (plain) |
|
Powers of 1000 not separated, and a dot is used for the decimal mark. |
1234567.890123 |
English |
|
Positive powers of 1000 are separated with commas, and a dot is used for the decimal mark. |
1,234,567.890123 |
SI (English) |
|
Powers of 1000 are separated with spaces, and a dot is used for the decimal mark. |
1 234 567.890 123 |
SI (French) |
|
Powers of 1000 are separated with spaces, and a comma is used for the decimal mark. |
1 234 567,890 123 |
Continental |
|
Positive powers of 1000 are separated with dots, and a comma is used for the decimal mark. |
1.234.567,890123 |
Continental (plain) |
|
Powers of 1000 are not separated, and a comma is used for the decimal mark. |
1234567,890123 |
Swiss |
|
Positive powers of 1000 are separated with apostrophes, and a dot is used for the decimal mark. |
1’234’567.890123 |
Indian |
|
Groups of digits in the integer part are separated with commas. The rightmost group is three digits, and other digits are grouped in pairs. A dot is used for the decimal mark. |
12,34,567.890123 |
Scientific |
|
A mantissa between 1 and 10, formatted using the ‘plain’ style, then the letter ‘e’, followed by a signed integer exponent. |
1.234567e+6 |
Warning
Note that some styles conflict with each other: for example, 1.234
is a number between 1 and 2 in English, while it’s the integer 1234 in French.
In the JavaScript runtime, these styles are defined in Numbas.util.numberNotationStyles
.
Numbers in JME¶
In JME code, and Mathematical expression parts, numbers are written in the “English (plain)” form only.
You can parse a string representing a number written in a different style using the parsenumber
function, and display it using a particular style using the formatnumber
function, or by giving a style code to dpformat
or sigformat
.