WARNING
Deprecated. Please use usePrecision
instead.
useToFixed
Reactive toFixed
.
Demo
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
Contributors
Anthony Fu
joypeng