OpenBI Docs Buy

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
ParameterTypeDescription
valueanyThe value to convert: a number, text, a logical, a date, datetime, time or duration; null gives null.
culturenullable text
optional
The culture text is read in, such as "nb-NO"; the query's culture when left out.
roundingModenullable 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.From reads 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

Int8.From, Int16.From, Number.From.

Last updated · OpenBI Studio 0.3.79