String to Float or Real?

General discussion on mikroPascal PRO for AVR.
Post Reply
Author
Message
corado
Posts: 401
Joined: 28 Mar 2009 11:03

String to Float or Real?

#1 Post by corado » 04 Aug 2013 18:28

Hallo,
is there way to String2Float conversion?

Carlos L R
Posts: 45
Joined: 28 Jun 2013 03:22

Re: String to Float or Real?

#2 Post by Carlos L R » 05 Aug 2013 00:46

You need to go to library management and install the library

User avatar
milos.vicentijevic
Posts: 965
Joined: 23 Apr 2013 08:09

Re: String to Float or Real?

#3 Post by milos.vicentijevic » 05 Aug 2013 10:32

Hello,

there is a way but unfortunately there is no such a library in mikroPascal, so you will have to write your own library for this purpose.

Best Regards,
Milos Vicentijevic

corado
Posts: 401
Joined: 28 Mar 2009 11:03

Re: String to Float or Real?

#4 Post by corado » 05 Aug 2013 10:56

Hallo,
the old additional string library works with some modifiaktion.
It will be great, if Mikroe will put more such thinks in his library.
Because a User to user Version is LunaAvr this is Pascal like for free.
But I use Mikroe because i think there will be a company that do thhis thinks ;-)

For this library i have to modificate all str2LongInt to strtoint...is this the same?
Or what is longint or longword now?

Code: Select all

function StrtoFloat(var data_str4 : string[17]) : real;
var txt10 : string[10];
    lungime, lungime1 : byte;
    pt1, pt2 : ^byte;
begin
  result := 0.;
  lungime := Str_Len(data_str4);
  if (lungime = 0) or (lungime > 17) then exit;
  lungime1 := Str_Chr(data_str4,'.');
  if lungime1 = 0 then exit;
  txt10 := '00000';
  pt1 := @data_str4[lungime1];
  pt1^ := 0;
  pt1 := pt1 + 1;
  pt2 := @txt10;
  inc(lungime1);
  while lungime1 < lungime do
    begin
      pt2^ := pt1^;
      pt2 := pt2 + 1;
      pt1 := pt1 + 1;
      inc(lungime1);
    end;
    if data_str4[0] = '-' then result := real(StrtoInt(data_str4)) - real(StrtoWord(txt10))/100000.0
    else result := real(StrtoInt(data_str4)) + real(StrtoWord(txt10))/100000.0;
end;

User avatar
milos.vicentijevic
Posts: 965
Joined: 23 Apr 2013 08:09

Re: String to Float or Real?

#5 Post by milos.vicentijevic » 07 Aug 2013 10:09

Hello,

longint is 32bit with scope -2147483648 .. 2147483647 . Instead of longword there is a dword. It is 32bit with scope 0 .. 4294967295.
Please, check Help Simple Types file for details.

Best Regards,
Milos Vicentijevic

Post Reply

Return to “mikroPascal PRO for AVR General”