Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

preventing real no. "1.30"  to "1.2999999999"

Posted on 1999-07-21
2
Medium Priority
?
155 Views
Last Modified: 2010-04-04
how can i get a real number without changing
its digits ex.
having a number "1.30" (string);
and "realno" variable of type real;
so..

 realno := strtofloat("1.30");
 
output

 1.2999999999 inside realno..

 how to prevent it and the output will be exactly
 1.30
0
Comment
Question by:mvalez
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 0 total points
ID: 1390328
You can't (unless you use something like BCD).

This is caused by the imprecise representation of many real numbers by the floating point types.

To get 1.3 back again jut convert it to a string with the same number of decimal places, eg:

RealStr := format('%.1f', [realno]);

Cheers,

Raymond.

0
 
LVL 1

Expert Comment

by:rpetruni
ID: 1390329
Hi, Mvalez...

try this:
FormatFloat('###,###,###,###,##0.00',realno);

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

704 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