Topic: Why are decimal numbers being round off ?
Titanium free asked 5 years ago
I am using mdbootstrap vue version in my project however when I insert rows in datatable and insert a decimal number from api like this:
0.00100000
It rounds off and just displays 0 in the table. When I hardcoded this value in a variable using javascript and displayed it, it showed me in exponential form like this for example:
1e-7
How should I avoid this ? I just want to display the number as it is and not round off anything.
Mikołaj Smoleński staff answered 5 years ago
Hello Titanium,
Could You please share with us an example of data row here? I just tested our Datatable component for decimal numbers and it's working correct.
One of my ideas is to change the number format into string before inserting into table.
Best regards
Titanium free commented 5 years ago
Well this is my code example:
var data = [{ "decimalNumber": 0.00010000 }];
for (var i = 0; i < Object.keys(data).length; i++) {
this.data.rows.push({
DecimalNumber: data[i].decimalNumber, //this one displays 0
DecimalNumber2: 0.00000010, // this one shows in exponential form
});
Titanium free commented 5 years ago
Oh nevermind, I just noticed that its the server which is sending rounded values so this has nothing to do with mdbootstrap now.
Thanks for help
Mikołaj Smoleński staff commented 5 years ago
I'm glad to read that You found the problem. I am available on the support channel for further problems.
Best regards
Titanium free commented 5 years ago
@Mikolaj Smolenski
I just checked it seems like the table is converting into exponential form. However rounding off to 0 is not being done because it was server issue.
But it is still converting into exponential form.
Mikołaj Smoleński staff commented 5 years ago
I am not sure if it's connected with our component. Please check again Your server configuration. Each time I pass decimal number to datatable it's not converting into expotential form.
Cheers
Titanium free commented 5 years ago
Can you pass a number with atleast 8 decimals ? like this one 0.00000001
Mikołaj Smoleński staff commented 5 years ago
Ok, now I can see the problem. We'll add it to the list of bugs and try to fix in one of the next releases.
Best regards
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Opened
- ForumUser: Free
- Premium support: No
- Technology: MDB Vue
- MDB Version: 4.8.2
- Device: HP
- Browser: Chrome
- OS: Windows 10
- Provided sample code: No
- Provided link: No