[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
6
Medium Priority
?
967 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 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

by:Epsylon
ID: 2650540
hpeter:

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

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

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

649 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