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

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
hpeterAsked:
Who is Participating?
 
alexstewart@betaConnect With a Mentor Commented:
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
 
EpsylonCommented:
Use Double instead of Single
0
 
hpeterAuthor Commented:
Double is an 8-byte number. But I need an 4-byte number from the string.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
jellisonCommented:
Don't really understand. Do you want the result in your example to be a real with just 4 decimal places -  4.0475 ?
0
 
ahalyaCommented:

Use the val function: e.g.


var r  : real;
     code : integer;

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


0
 
EpsylonCommented:
hpeter:

Single is just not precise enough. Why does it have to be Single?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.