Précédent   Forum du club des développeurs et IT Pro > Autres langages > Pascal > Flash Pascal
Flash Pascal Forum d'entraide sur la création de fichiers Flash en Object Pascal
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 04/12/2012, 22h04   #1
Archimède
Membre émérite
 
Avatar de Archimède
 
Homme anthony
Enseignant
Inscription : avril 2005
Messages : 1 026
Détails du profil
Informations personnelles :
Nom : Homme anthony
Localisation : France, Charente Maritime (Poitou Charente)

Informations professionnelles :
Activité : Enseignant
Secteur : Enseignement

Informations forums :
Inscription : avril 2005
Messages : 1 026
Points : 975
Points : 975
Par défaut Conversion de string en number

J'ai tenté de déclarer et d'utiliser :
Code :
1
2
 
 function parseFloat(expression:String) : Number external;
en l'ajoutant à l'unité Flash8 mais elle ne fonctionne pas..

Comment convertir une string d'un TextField.text en float (number)

Une fonction du type strtofloat...

merci
__________________
Citation:
tout développeur plongé dans son code subit une poussée d'urticaire de bas en haut égale au poids du volume d'unités qu'il ajoute.
Archimède est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/12/2012, 06h54   #2
Paul TOTH
Expert Confirmé Sénior
 
Avatar de Paul TOTH
 
Homme Paul TOTH
Freelance
Inscription : novembre 2002
Messages : 4 395
Détails du profil
Informations personnelles :
Nom : Homme Paul TOTH
Âge : 43
Localisation : Réunion

Informations professionnelles :
Activité : Freelance
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : novembre 2002
Messages : 4 395
Points : 10 736
Points : 10 736
c'est pourtant bien cela...avec le point comme séparateur

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 
program Project2;
 
{$FRAME_WIDTH 550}
{$FRAME_HEIGHT 400}
{$FRAME_RATE 12}
{$BACKGROUND $FFFFFF}
 
uses
  Flash8;
 
function parseFloat(expression: string): Number external;
 
var
  t: TextField;
begin
  t := TextField.Create(_root, '', 1, 10, 10, 100, 100);
  t.text := FloatToStr(parseFloat('1.25') + parseFloat('0.10'));
end.
et accessoirement tu peux aussi déclarer
Code :
1
2
 
function StrToFloat(expression: string): Number external 'parseFloat';
__________________
Developpez.com: Mes articles, forum FlashPascal
Entreprise: Execute SARL
Produits : UPnP, RemoteOffice, FlashPascal
Embarcadero : Ile de la Réunion, Dephi, C++Builder, RADPHP...TVA à 8,5%
Paul TOTH est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 05/12/2012, 09h10   #3
Archimède
Membre émérite
 
Avatar de Archimède
 
Homme anthony
Enseignant
Inscription : avril 2005
Messages : 1 026
Détails du profil
Informations personnelles :
Nom : Homme anthony
Localisation : France, Charente Maritime (Poitou Charente)

Informations professionnelles :
Activité : Enseignant
Secteur : Enseignement

Informations forums :
Inscription : avril 2005
Messages : 1 026
Points : 975
Points : 975
Merci, en effet, ça ne venait pas de ParseFloat... J'avais un événement onKeyDown et j'ai oublié de metttre Key.addlistener(montextfield)...

Autant pour moi

merci encore. sympa la déclaration strtofloat à partir de ParseFloat...

je retiens.

__________________
Citation:
tout développeur plongé dans son code subit une poussée d'urticaire de bas en haut égale au poids du volume d'unités qu'il ajoute.
Archimède est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 06/12/2012, 22h24   #4
Roland Chastain
Membre Expert
 
Homme Roland Chastain
Inscription : décembre 2011
Messages : 686
Détails du profil
Informations personnelles :
Nom : Homme Roland Chastain
Âge : 39
Localisation : Mali

Informations professionnelles :
Secteur : Enseignement

Informations forums :
Inscription : décembre 2011
Messages : 686
Points : 1 001
Points : 1 001
C'est bon à savoir, tout ça.

J'ai voulu écrire un petit exemple qui utilise la fonction StrToFloat. J'ai fait un programme qui convertit un nombre décimal en fraction :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
 
program Fractions;
 
{$FRAME_WIDTH 400}
{$FRAME_HEIGHT 240}
 
uses
  Flash8;
 
function StrToFloat(expression: string): Number external 'parseFloat';
 
type
  tFraction = record
                n: integer; // numérateur
                d: integer; // dénominateur
              end;
 
const
  dmax = 10000; // borne supérieure pour la recherche du dénominateur
 
function Fraction(nombre: number): tFraction;
var
  d: integer;
  e: number; // erreur
  m: number; // moindre erreur
begin
  for d := 1 to dmax do
  begin
    e := Abs(nombre * d - Trunc(Math.Round(nombre * d)));
    if d = 1 then
      m := e
    else
      if e < m then
        m := e;
  end;
  for d := 1 to dmax do
  begin
    e := Abs(nombre * d - Trunc(Math.Round(nombre * d)));
    if e = m then
    begin
      Result.d := d;
      Result.n := Trunc(Math.Round(nombre * d));
      Exit;
    end;
  end;
end;
 
type
  tEditBox = class(textField)
    procedure onKeyDown;
  end;
 
var
  e: tEditBox;
  t: textField;
 
procedure tEditBox.onKeyDown;
var
  f: tFraction;
begin
  if key.getAscii = 13 then
  begin
    f := Fraction(StrToFloat(e.text));
    t.text := "Meilleur résultat: " + IntToStr(f.n) + "/" + IntToStr(f.d);
  end;
end;
 
begin
  with textField.Create(_root, 'label', 0, 0, 0, stage.width - 1, 4 * 16 + 4) do
  begin
    SetNewTextFormat(textFormat.Create('Courier New', 12));
    text := "FlashPascal 2."#13
          + "Conversion d'un nombre décimal en fraction."#13
          + "Veuillez saisir un nombre décimal:";
  end;
 
  e := tEditBox.Create(_root, 'input', 1, 0, 3 * 16 + 4, stage.width - 1, 16 + 4);
 
  e.setNewTextFormat(textFormat.Create('Courier New', 12));
  e.type := 'input';
  e.border := TRUE;
  e.borderColor := $e0e0e0;
  selection.setFocus(e);
  key.addListener(e);
 
  t := textField.Create(_root, 'output', 2, 0, 3 * 16 + 4 + 16 + 4, stage.Width - 1, stage.height - (3 * 16 + 4 + 16 + 4));
 
  t.SetNewTextFormat(textFormat.Create('Courier New', 12));
 
  stage.scaleMode := 'noScale';
end.
Fichiers attachés
Type de fichier : swf Fractions.swf (875 octets, 0 affichages)
__________________
L'Art est long et le Temps est court.
Roland Chastain est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Cette discussion est résolue.
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 17h48.


 
 
 
 
Partenaires

Hébergement Web