Solved

String->Single value (StrToFloat doesn't  work in D3)

Posted on 2000-03-23
6
934 Views
Last Modified: 2012-05-07
How can I convert string to single value? StrToFloat get an extended value.
Example:
var e:single;
...
e:=StrToFloat('0,0475');
and e=0,0474999... And this is my problem.
An idea?
Thank's
0
Comment
Question by:hpeter
6 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 2649740
Use Double instead of Single
0
 

Author Comment

by:hpeter
ID: 2649901
Double is an 8-byte number. But I need an 4-byte number from the string.
0
 
LVL 1

Expert Comment

by:jellison
ID: 2649965
Don't really understand. Do you want the result in your example to be a real with just 4 decimal places -  4.0475 ?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 7

Expert Comment

by:ahalya
ID: 2649981

Use the val function: e.g.


var r  : real;
     code : integer;

begin;
val('12.345', r, code);
if Code <> 0 then error;
end;


0
 
LVL 2

Accepted Solution

by:
alexstewart@beta earned 10 total points
ID: 2650077
Any fixed size/format binary floating point system will be 'wrong' for numbers like 1/3, which do not have a finite binary representation (1/3=0.11111111...). So your question seems to be about "rounding". If you know how many digits you want you can do something like...

xsingle:=round(xextended*10000)/10000;

Or look at the Currency      floating point type, (it is like a fixed point format).

The Currency type is good for representing money numbers (As you might guess!)

You can also use string conversions to do rounding, in scientific notation. The problem is related to labeling of graph axes.

Alex
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2650540
hpeter:

Single is just not precise enough. Why does it have to be Single?
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now