Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to obtain a number of decimal places for BCD value? 1

Status
Not open for further replies.

Delphard

Programmer
Jul 22, 2004
144
RS
BcdScale Routine seems to work unexpected...
 
Have you tried this? (from D7 Help - TBcd type): "You can create a Variant that represents a TBcd value using the VarFMTBcdCreate function. In fact, the easiest way to manipulate TBcd values is to create Variants for them and use the built-in operators provided by the Variant type."

Roo
Delphi Rules!
 
Decimal places are not normally stored within BCD values. Therefore, the decimal place value is implied in the type and not explicit (basically it's whatever you say it is).

Any BCD value has an accompanying value (most times) which indicates the number of decimal places and should be read to get the value and changed to change the number of decimal places.
 
Glen was right: 'the decimal place value is implied in the type and not explicit'.

So, let me formulate question like this:
HOW TO FIND NUMBER OF DECIMAL PLACES FOR AN DECIMAL NUMBER?

For example: If user input 12.345, need to get result 3.
 
Brute force:
(using the jclStrings library)
Code:
iDecimals := length(StrAfter('.',floattostr(f)));

StrAfter can be replaced with Pos but the jcl uses assembler to keep things fast.
 
From what I gather, BCDScale would be what you want. BCDPrecision is the total digit count if I understand correctly. The BCD value is stored in a record (Tbcd) along with other values which determine scale, precision, sign, and so on.

However, you may be running into a separate issue. What exactly is happening? And what are you doing precisely with BCDs? Are you sure you are getting a proper result?

See this for some details on why I'm asking...
 
Nevermind the post above, I think I misread the intention. If you are talking text input, something like DjangMan's post will do nicely (though you might want to check for valid input before you do such a thing)
 
@DjangMan
Tnx, but don't know where to find jclStrings library!?
Will use Pos instead...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top