Skip to content

science.percentage.wren

clsource edited this page Oct 8, 2020 · 4 revisions

A simple class to convert percentages to strings and viceversa.

  • Example:
import "./science/percentage" for Percentage
import "./science/percentage" for Pct
  • Since: 1.0.0

API

Holds the number one hundred

  • Signature: static var onehundred:Num = 100

Hodls the number one

  • Signature: static var one:Num = 1.0

Creates a new string from a given percentage number.

  • Example:
Percentage.encode(0.5) // => 50%
  • Since: 1.0.0
  • Signature: static func encode(number:Num) -> String
  • Parameter number: A number from 0 to 1 to convert to percentage.
  • Returns: A percentage including %.
  • Throws: Fiber.abort() if the value is not a number.

Creates a new number from a given percentage string.

  • Example:
Percentage.decode("50%") // => 0.5
  • Since: 1.0.0
  • Signature: static func decode(number:Num) -> String
  • Parameter value: A string or number to decode.
  • Returns: A number from 0 to 1.
  • Throws: Fiber.abort() if the value is not a number or string.