DONE: A way to round numbers to two decimal places?

+1 vote

Is there a way to round numbers to two decimal places? I have inputted 0.15 yet I am seeing 0.15000000590464.

in Features (Done) by (7.0k points)
edited by

1 Answer

0 votes
Best answer

dbFront has supported numeric formatting for some time but this only applied to reports and not the edit form.

As of, you can configure dbFront to automatically round decimal and floating point numbers to a specified number of digits. The rounding is done on read and display. It is still possible to save numbers with extra decimal places but the values will be rounded once the data is read back from the database.

You can configure the number of decimal digits in the field preferences.

Rounding Not Recommended

We have added the rounding functionality to dbFront at our users request, but our recommendation is that it should be used sparingly.

The primary risk is that the user can't see and edit exactly what is in the database. They can only see the rounded value. This has the potential to cause confusion and result in calculation errors.

Floats Not Recommended for Business Data

Another part of the problem is that you are likely using a floating point data type like Float, Single or Real. It is generally not a good idea to use floating point numbers to store decimal values because they store in-exact representations of the numbers you entered. This is especially dangerous if mixed with additional rounding.

An old floating-point joke:

If I cut a cake in three, each piece is 0.33 of the cake. If I stick
all three pieces back together that gives me 0.99 of the cake. Where
has the rest of the cake gone?
— Simple. That’s the little bit stuck on the knife

For a more complete writeup see: The Dangers of using Float or Real Datatypes

Recommended type is "Numeric" with a specifed decimal precision

The recommended datatype for Business numeric values is Numeric. The Numeric datatype allows you to specify the decimal precision and dbFront respects and directly uses the precision and scale.

With the Numeric datatype the user sees exactly what is in the database and there is no possibility of confusion.

by (64.4k points)
selected by
Welcome to the dbFront Q&A site, where you can ask questions and receive answers from other members of the community.
 | Minimalist Answer Theme by Digitizor Media
Powered by Question2Answer