Skip to content
On this page

WARNING

Deprecated. Please use usePrecision instead.

useToFixed

Category
Export Size
300 B
Package
@vueuse/math
Last Changed
7 months ago

Reactive toFixed.

Demo


input: digits:
2
type:
math:
value:314.16
typeof value:number

Usage

ts
import { useToFixed } from '@vueuse/math'

const value = ref(3.1415)
const result = useToFixed(value, 2) // 3.14

const stringResult = useToFixed(value, 5, {
  type: 'string'
}) // '3.14150'

const ceilResult = useToFixed(value, 2, {
  math: 'ceil'
}) // 3.15

const floorResult = useToFixed(value, 3, {
  math: 'floor'
}) // 3.141
import { useToFixed } from '@vueuse/math'

const value = ref(3.1415)
const result = useToFixed(value, 2) // 3.14

const stringResult = useToFixed(value, 5, {
  type: 'string'
}) // '3.14150'

const ceilResult = useToFixed(value, 2, {
  math: 'ceil'
}) // 3.15

const floorResult = useToFixed(value, 3, {
  math: 'floor'
}) // 3.141

Type Declarations

typescript
export interface FixedTypes {
  type?: "string" | "number"
  math?: "floor" | "ceil" | "round"
}
/**
 * @deprecated use `usePrecision` instead
 */
export declare function useToFixed(
  value: MaybeComputedRef<number | string>,
  digits: MaybeComputedRef<number>,
  options?: MaybeComputedRef<FixedTypes>
): ComputedRef<number | string>
export interface FixedTypes {
  type?: "string" | "number"
  math?: "floor" | "ceil" | "round"
}
/**
 * @deprecated use `usePrecision` instead
 */
export declare function useToFixed(
  value: MaybeComputedRef<number | string>,
  digits: MaybeComputedRef<number>,
  options?: MaybeComputedRef<FixedTypes>
): ComputedRef<number | string>

Source

SourceDemoDocs

Contributors

Anthony Fu
joypeng

Changelog

v9.1.0 on 8/4/2022
790ef - fix: deprecated in favor of usePrecision
v9.0.1 on 7/29/2022
b916a - feat: new function (#2003)

Released under the MIT License.