I am currently facing an issue in my Angular project where I am attempting to read a JSON file. This file is stored in the assets folder and contains decimal values such as:
{
"valueA": 0.40000000000002,
"valueB": 23.99999999999999995
}
The problem arises when I import the file and the values are rounded to:
{
"ValueA": 0.4
"ValueB": 25
}
Is there a way to retrieve the JSON with the exact decimal digits from the source? Alternatively, is it possible to convert them into strings? Unfortunately, modifying the source to split the numbers at the dot or save them as strings is not an option for me. Although I could potentially edit it during the data seeding pipeline process, this approach seems messy.
Currently, my JSON file is imported and utilized in the following manner:
import MyJson from 'src/assets/MyJson.json'
export class MyService {
private myJson = Object.assign(MyJson);
public getFieldsIWant() {
return this.myJson.theFields.iWant;
}
}
It seems that the issue lies within the first line of import {...
. When I print the imported file, the decimal places have already been "converted". Is there an alternative method to import JSON files in TypeScript to avoid this issue (I have already attempted importing via httpClient with the same outcome)?