Extract the decimals from a float.

Posted on 2002-06-13
Last Modified: 2010-04-04
How can I extract the decimals and the other part of a float?

for example if I have


and want them in 2 variables.

a = 40011
b = 9786

how can I do that?
Question by:wqclatre

Expert Comment

ID: 7077419

Int() and Frac()

Frac gives You 0.9786 If You want to it to be an Integer value You must know how many decimals You vant. Example

I = Int(Frac(X)*10000) // gives an integer betveen 0 and 9999.

LVL 45

Accepted Solution

aikimark earned 50 total points
ID: 7077423
1. assign value to an integer variable
2. assign expression (value - (1)VARIABLEvalue) to a real variable, where (1)VARIABLEvalue is the integer variable used in step 1.
LVL 14

Expert Comment

ID: 7077424
a := Int(40011.9786);
b := Frac(40011.9786);
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

LVL 14

Expert Comment

ID: 7077425
ooops... too late :)
LVL 27

Expert Comment

ID: 7077520
too late, too :-))
LVL 45

Expert Comment

ID: 7078124
This question was "pounced upon" wasn't it.  So many answers, just waiting for a question.

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to fill array with TArray.Create? 14 90
delphi exception 7 64
Not able to call Delphi XE10 dll function from Delphi 6.0 4 28
enhance the following code 3 32
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question