Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
August 4th, 2010, 07:48 AM
 banaru
Registered User

Join Date: Aug 2010
Posts: 3
Time spent in forums: 29 m 43 sec
Reputation Power: 0
Firebird rounding decimals number

Hi!
I have a firebird database (vs. 2.5 RC2) with a table with ColumnA and ColumnB, both numeric, lenght 6, scale 2.
I want to do ColumnA * ColumnB, but the rezult is numeric, 6, 4.
Eg. ColumA 45,67
ColumnB 33,38
ColumA * ColumnB should be 45,67 * 33,38 = 1524,4646
But i want 1524,46.
How can do this.
Thanks!

#2
August 4th, 2010, 08:55 AM
 mIRCata
Contributing User

Join Date: Sep 2006
Location: Plovdiv. Bulgaria
Posts: 217
Time spent in forums: 2 Days 10 h 38 m 6 sec
Reputation Power: 12
Quote:
 Originally Posted by banaru Hi! I have a firebird database (vs. 2.5 RC2) with a table with ColumnA and ColumnB, both numeric, lenght 6, scale 2. I want to do ColumnA * ColumnB, but the rezult is numeric, 6, 4. Eg. ColumA 45,67 ColumnB 33,38 ColumA * ColumnB should be 45,67 * 33,38 = 1524,4646 But i want 1524,46. How can do this. Please help me. Thanks!

round(ColumA * ColumnB,2)

#3
August 4th, 2010, 03:42 PM
 banaru
Registered User

Join Date: Aug 2010
Posts: 3
Time spent in forums: 29 m 43 sec
Reputation Power: 0
Quote:
 Originally Posted by mIRCata round(ColumA * ColumnB,2)

Thanks for you response.
The result is 1524,4600
Rounding is correct but is adding two zeros and i don't want.
Whay?
For editing firebird i use Database Workbench 4.0.3 but i have the same result in IBManager.

#4
August 5th, 2010, 10:08 AM
 banaru
Registered User

Join Date: Aug 2010
Posts: 3
Time spent in forums: 29 m 43 sec
Reputation Power: 0
Quote:
 Originally Posted by banaru Thanks for you response. The result is 1524,4600 Rounding is correct but is adding two zeros and i don't want. Whay? For editing firebird i use Database Workbench 4.0.3 but i have the same result in IBManager.

#5
August 5th, 2010, 04:27 PM
 clivew
Contributing User

Join Date: Jan 2006
Posts: 2,047
Time spent in forums: 1 Week 6 Days 3 h 27 m 46 sec
Reputation Power: 382
I suspect you need to look at the formatting properties of your tool.
I probably is not a Firebird issue

#6
June 19th, 2013, 03:28 PM
 Traehflow
Registered User

Join Date: Jun 2013
Posts: 1
Time spent in forums: 5 m 40 sec
Reputation Power: 0
That depends on the data type of your column. You can cast to a decimal with two digits after the point in this way:

cast( round(ColumA * ColumnB,2) as decimal(17, 2))

#7
July 9th, 2013, 11:13 AM
 emailx45
Contributing User

Join Date: Sep 2008
Posts: 51
Time spent in forums: 11 h 33 m 40 sec
Reputation Power: 6

Fields type NUMERIC behave cast.

Thus, the problem in the result of the expression should not be at the Firebird, but, in the definition of the field or variable used to welcome such an outcome.

Try the EDITOR OF FIELDS from Dataset, see the settings that are being used for PRECISION and SCALE. (size for anyone)

Example: Fields type CURRENCY using SCALE = 4 for default in EDITOR FIELDS.

As a general rule for multiplication, is the sum of the amount of decimal places when showering with parts number WHOLE AND DECIMAL. Example: * iiii.dd iii.ddd = ix.ddddd

Thus, as the division is automatic use of regular tithe.
1 / 3 = 0.3333333333...

In Delphi, goes to 15 digits significants
In Firebird, max 18 digits significats (see the version)

http://www.firebirdfaq.org/faq340/

http://www.firebirdfaq.org/ (Search for "NUMERIC")

NOTE: In Delphi, you can use "MASK EDIT" for fields formatation.

Last edited by emailx45 : July 9th, 2013 at 11:23 AM.

 Viewing: Dev Shed Forums > Databases > Firebird SQL Development > Firebird rounding decimals number