Skip to content

percent

Input a number num and a total total (default is 100), and return a formatted percentage string. An optional parameter fixed is available to control the number of decimal places, defaulting to 2.

Added in v0.0.1

Usage

ts
import { percent } from 'parsnip-kit'

percent(50) // '50.00%'
percent(25, 100) // '25.00%'
percent(75, 200) // '37.50%'
percent(75, 200, 0) // '38%'
percent(0) // '0.00%'

API

Arguments

ArgTypeOptionalDefaultDescription
numnumberfalseundefinedThe number to calculate
totalnumbertrue100Total value
fixednumbertrue2Decimal places

Returns

Type
string