• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 975
  • Last Modified:

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
0
hpeter
Asked:
hpeter
1 Solution
 
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
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
alexstewart@betaCommented:
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:
hpeter:

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now