Solved

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

Posted on 2000-03-23
6
944 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Title # Comments Views Activity
Find and Replace Stream with 0s 8 69
control image tags in a string ? 12 140
Delphi: making a BW image transparent 10 57
Twebbrowser add css to the header 3 27
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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…

790 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