Strtofloat en pascal
Résolu
-
-
-
Bonjour,
je débute avec le langage de programmation et je voudrais savoir si à partir du code qui suit, je peux convertir ma chaîne en Extended
Cordialement, Debutant en webmastering
je débute avec le langage de programmation et je voudrais savoir si à partir du code qui suit, je peux convertir ma chaîne en Extended
program SaisieUser; var i : integer; var test : boolean; var chaine : string; var chainefloated : Extended; //Commentée car msg erreur : "Paramater S not used" //function StrToFloat(const S: string):Extended; //Vérifie nombre compis entre 0.01 et 1milliard-0.01 procedure verifsaisie(var ch: string); begin repeat writeln('Veuillez renseigner un montant d''Euro valide'); writeln('PS : le séparateur entre Euro et centimes est le . '); readln(ch); for i:=1 to length(ch) do begin if ((length(ch) > 0) and (length (ch) <= 12)) then if ((ch[i] in ['0'..'9']) or (ch[i] = '.')) then if (ch[i] = '.') then if (length(ch) <> i) and (((length(ch) - i) = 1) or ((length(ch) - i) = 2)) then if (not(ch[i-1] = '0') and (ch[i+1] = '0') and (ch[i+2] = '0')) then test:=true else test:=false; end; until test=true; end; begin verifsaisie(chaine); write(chaine); readln(); //chainefloated := StrToFloat(chaine); end.
Cordialement, Debutant en webmastering
EDIT : Ajout des balises de code (la coloration syntaxique).
Explications disponibles ici : ICI Merci d'y penser dans tes prochains messages. |
A voir également:
- Strtofloat en pascal
- Turbo pascal - Télécharger - Édition & Programmation
- My pascal - Télécharger - Édition & Programmation
- Dev pascal - Télécharger - Édition & Programmation
- Le protocole assure que la communication entre l'ordinateur de pascal et le serveur de visiodoct est car les informations seront avant d'être envoyées. - Forum Pascal
- Probleme en pascal - Forum Pascal
1 réponse
program Project2; var S : String[12]; L, I, DecimalWidth : Integer; X, Montant: Real; begin DecimalSeparator := '.'; DecimalWidth := 2; // Nombre de chiffre aprés la virgule Write('Montant en Euro : '); ReadLn(S); L := Length(S); X := 0.00; for I := 1 to L do begin if S[I] in['0' .. '9', '.'] then if Pos('.', S) = L - DecimalWidth then X := StrToFloat(S); { La saisie est valide, sinon X garde sa valeur initiale } end; WriteLn(X); { Sinon la procédure prédéfinie Val(S, V, Code) s'en charge } repeat Write('Montant en Euro : '); ReadLn(S); Val(S, Montant, I); { Si S forme un flottant valide, S est copiée dans Montant, sinon I indique l'emplacement de l'erreur dans les rangs de S } if I <> 0 then WriteLn('Erreur de saisie !. Recommencez'); until I = 0; WriteLn(Montant); ReadLn; { TODO -oUser -cConsole Main : placez le code ici } end.