NextJS response.json converts decimal to string
Unanswered
Oak rough bulletgall wasp posted this in #help-forum
Oak rough bulletgall waspOP
import { PrismaClient } from "@prisma/client";
const handler = async (req, res) => {
const prisma = new PrismaClient();
const result = await prisma.Test.findMany({});
console.log(result);
res.status(200).json(result);
//res.status(200).json({ name: "John Doe", age: 34, salary: 12345.75 });
};
export default handler;
This returns [{"id":"dafsdfd","name":"John Doe","age":35,"salary":"1234.56","updatedAt":"2023-11-21T08:45:55.000Z"}]
Though the console log prints correctly as follows. [ { id: 'dafsdfd', name: 'John Doe', age: 35, salary: 1234.56, updatedAt: 2023-11-21T08:45:55.000Z } ]
However, if I use res.status(200).json({ name: "John Doe", age: 34, salary: 12345.75 }); It is returing the decimal correctly as below.
How can I return a decimal from an object without converting to string in NextJS ?
const handler = async (req, res) => {
const prisma = new PrismaClient();
const result = await prisma.Test.findMany({});
console.log(result);
res.status(200).json(result);
//res.status(200).json({ name: "John Doe", age: 34, salary: 12345.75 });
};
export default handler;
This returns [{"id":"dafsdfd","name":"John Doe","age":35,"salary":"1234.56","updatedAt":"2023-11-21T08:45:55.000Z"}]
Though the console log prints correctly as follows. [ { id: 'dafsdfd', name: 'John Doe', age: 35, salary: 1234.56, updatedAt: 2023-11-21T08:45:55.000Z } ]
However, if I use res.status(200).json({ name: "John Doe", age: 34, salary: 12345.75 }); It is returing the decimal correctly as below.
How can I return a decimal from an object without converting to string in NextJS ?