3.0.2 • Published 3 years ago
decimal-type v3.0.2
decimal-type
A collection of helper functions for working with decimal numbers in various JS/TS environments.
Installation
# With Yarn
yarn add decimal-type
# or with npm
npm i decimal-typeUsage
As this is more like a bundle, you are free to combine the functions you need. Check the Examples section for some use cases.
Examples
Nest.js / GraphQL (code-first) / Prisma / class-transformer
import { DecimalScalar, DecimalType } from 'decimal-type';
import { Field, InputType } from '@nestjs/graphql';
import { Decimal } from '@prisma/client/runtime';
@InputType()
export class NewTransactionInput {
@Field()
name: string;
@Field(() => DecimalScalar)
@DecimalType()
amount: Decimal;
}NOTE: Don't forget to register the
DecimalScalarscalar with Nest.js. See here for more information.INFO: If the
@DecimalType()decorator is not used,class-transformerwill not know how to transform theDecimaltype returned by theDecimalScalarscalar into a newDecimalinstance.