Log On
Embarcadero Home
Watch, Follow, &
Connect with Us
Share This
QualityCentral
Communities
Articles
Blogs
Resources
Downloads
Help
QualityCentral
Delphi-BCB
RTL
Delphi
Arithmetic
ConvUtils
Date - Time
DateUtils
File Management
Format + Float
Input/Output
Math Unit
Memory, Pointer, Address
Null-terminated strings
Other Classes
Other RTL
Pascal Strings
Regular Expressions
RTL Exceptions
Text Files
Thread support
Typed/Untyped Files
WinAPI
You are not logged in.
Help
Print
Public Report
Report From:
Delphi-BCB/RTL/Delphi/Format + Float
[ Add a report in this area ]
Report #:
79820
Status:
Closed
Bug in FormatBcd() function
Project:
Delphi
Build #:
14.0.3513.24210
Version:
14.0
Submitted By:
Peter Wolf
Report Type:
Basic functionality failure
Date Reported:
11/26/2009 1:51:33 AM
Severity:
Commonly encountered problem
Last Updated:
3/20/2012 2:24:39 AM
Platform:
All platforms
Internal Tracking #:
273810
Resolution:
Fixed
(Resolution Comments)
Resolved in Build:
:
16.0.4152.39274
Duplicate of:
None
Voting and Rating
Overall Rating:
No Ratings Yet
0.00 out of 5
Total Votes:
None
Description
FormatBcd() function outputs wrong result when the number on input is rounded up by the function and the the right padding with 0's is requested by the format used.
The result of the function is not right-padded with zeroes as compared to FormatFloat() function using the same number and format.
Added by Sysop
<<<<<<<<<
I should have used DoubleToBcd() function instead of CurrToBcd() in the demo of course, but it doesn't matter, the resut is the same.
And, This issue similar to QC#42792.
>>>>>>>>>
Steps to Reproduce:
This short demo reveals the bug:
uses
Dialogs, FMTBcd;
procedure Reporoduce;
const
Format = '0.00';
var
AFloat: Double;
ABcd: TBcd;
begin
// Expected result: '1.90'
AFloat := 1.895;
CurrToBCD(AFloat, ABcd, MaxBcdPrecision, MaxBcdScale);
ShowMessage(FormatFloat(Format, AFloat)); // output: '1.90'
ShowMessage(FormatBcd(Format, ABcd)); // output: '1.9'
// Expected result: '2.00'
AFloat := 1.995;
CurrToBCD(AFloat, ABcd, MaxBcdPrecision, MaxBcdScale);
ShowMessage(FormatFloat(Format, AFloat)); // output: '2.00'
ShowMessage(FormatBcd(Format, ABcd)); // output: '2'
end;
Workarounds
None
Attachment
None
Comments
Peter Wolf at 11/27/2009 1:13:54 AM
-
I should have used DoubleToBcd() function instead of CurrToBcd() in the demo of course, but it doesn't matter, the resut is the same.
Tomohiro Takahashi at 11/27/2009 7:02:36 PM
-
This issue similar to QC#42792.
Peter Wolf at 12/8/2009 1:10:50 AM
-
I admit it's similar, but not the same. In addition the bug still persists in D2010, however QC#42792 was already fixed.
Dick Boogaers at 12/8/2009 4:17:07 AM
-
The bug is in the function RoundAt in unit FMTbcd. In that function there is this code:
if (Position < Length(Value)) and (DecPos < Position) then
begin
PP := PChar(Value) + ((Position -1));
P := PP+1;
if Byte(P^) >= 53 then { if '5' or greater }
PP^ := Char(Byte(PP^)+1);
while (Position > 0) and ((Byte(PP^) > 57) or (PP^ = Dot)) do {if greater than '9' then }
begin
if PP^ <> Dot then
PP^ := '0';
Dec(Position);
Dec(PP);
if PP^ <> Dot then
PP^ := Char(Byte(PP^)+1);
end;
Because the value of "Position" is needed later on to return the correct substring, it should not be overwritten in this loop.
The correct code goes something like this:
if (Position < Length(Value)) and (DecPos < Position) then
begin
PP := PChar(Value) + ((Position -1));
P := PP+1;
if Byte(P^) >= 53 then { if '5' or greater }
PP^ := Char(Byte(PP^)+1);
DecPos := Position; // <<< Copy Position to temp
while (DecPos > 0) and ((Byte(PP^) > 57) or (PP^ = Dot)) do // <<< Use temp i.s.o. Position
begin
if PP^ <> Dot then
PP^ := '0';
Dec(DecPos); // <<< Use temp i.s.o. Position
Dec(PP);
if PP^ <> Dot then
PP^ := Char(Byte(PP^)+1);
end;
View Your Reports
Search
Server Response from: ETNACODE01
Developer Tools
Blackfish SQL
C++Builder
Delphi
FireMonkey
Prism
InterBase
JBuilder
J Optimizer
HTML5 Builder
3rdRail & TurboRuby
Database Tools
Change Manager
DBArtisan
DB Optimizer
ER/Studio
Performance Center
Rapid SQL
Technical Articles
Tutorials
White Papers
Press Releases
Newsletters
Add Content (GetPublished)
Audio
Audio & Video
Video
Bugs & Suggestions (QualityCentral)
Discussion Forums
Examples (CodeCentral)
Tags
Technology Partners
Downloads
Free Trials
Registered User Downloads
Beta Programs
Add Content (GetPublished)
Articles
Blogs
Bugs & Suggestions (QualityCentral)
Discussion Forums
Examples (CodeCentral)
Member Services
About
Connect with Us