[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
Solved

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

Posted on 2000-03-23
Medium Priority
967 Views
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
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

LVL 13

Expert Comment

ID: 2649740
0

Author Comment

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

LVL 1

Expert Comment

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

LVL 7

Expert Comment

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

alexstewart@beta earned 30 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

ID: 2650540
hpeter:

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

## Featured Post

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
###### Suggested Courses
Course of the Month14 days, 14 hours left to enroll