Solved

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

Posted on 2000-03-23
6
947 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
[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
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…

697 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