Byte.From
A value as a byte, a whole number from 0 to 255 (Byte.Type), its fraction rounded away.
Group: Values, types and errors. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Byte.From(value as any, optional culture as nullable text, optional roundingMode as nullable number) as nullable number
| Parameter | Type | Description |
|---|---|---|
value | any | The value to convert: a number, text, a logical, a date, datetime, time or duration; null gives null. |
culture | nullable text optional | The culture text is read in, such as "nb-NO"; the query's culture when left out. |
roundingMode | nullable number optional | Where a half goes: RoundingMode.ToEven (the default), RoundingMode.AwayFromZero, RoundingMode.Up, RoundingMode.Down or RoundingMode.TowardZero. Any other fraction goes to the nearest number whatever the mode. |
Returns
nullable number. The whole number; null for null.
Remarks
- Text is read in the culture, the way
Number.Fromreads it; a value that isn't a number is an error. - A fraction is rounded to the nearest whole number. A half goes to the even neighbour unless a rounding mode says otherwise: 4.5 becomes 4 and 5.5 becomes 6. The mode is used for a half only, so 12.1 is 12 even with
RoundingMode.Up. - A number outside the type's range is an error, as in Power Query: below 0 or above 255.
Examples
The largest byte, from text
Byte.From("255")
255
A half, to even
Byte.From(12.5)
12
A half rounded up
Byte.From(12.5, null, RoundingMode.Up)
13