Val/de: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Val/de
| Old | New | Line | |
|---|---|---|---|
| 1 | + | # Val | |
| 2 | + | ||
| 3 | + | ## Beschreibung | |
| 4 | + | ||
| 5 | + | Mit **Val**, kann man einen **String** in einen numerischen Wert konvertieren. | |
| 6 | + | ||
| 7 | + | > **Note:** Bei Float-Typen muss beachtet werden, das immer ein **Punkt** als Dezimaltrenner verwendet wird, egal wie die Ländereinstellungen des OS eingestellt sind. | |
| 8 | + | ||
| 9 | + | ## Beispiel | |
| 10 | + | ||
| 11 | + | ``` pascal | |
| 12 | + | var | |
| 13 | + | s: string; | |
| 14 | + | e, i: integer; | |
| 15 | + | f: single; | |
| 16 | + | ||
| 17 | + | begin | |
| 18 | + | s := '123'; | |
| 19 | + | Val(s, i, e); | |
| 20 | + | WriteLn(i); | |
| 21 | + | s := '123.456'; | |
| 22 | + | Val(s, f, e); | |
| 23 | + | WriteLn(f); | |
| 24 | + | ``` | |
| 25 | + | ||
| 26 | + | Wen der 3. Parameter \<\> 0 ist, konnte **keine** Konvertierung durchgeführt werden, als numerischen Wert wird dann **0**, oder **0.0** zurückgegeben. | |
| 27 | + | ||
| 28 | + | ``` pascal | |
| 29 | + | var | |
| 30 | + | s: string; | |
| 31 | + | e, i: integer; | |
| 32 | + | f: single; | |
| 33 | + | ||
| 34 | + | begin | |
| 35 | + | s := 'abc'; | |
| 36 | + | Val(s, f, e); | |
| 37 | + | if e <> 0 then begin | |
| 38 | + | WriteLn('Ungültiger Wert !'); | |
| 39 | + | end; | |
| 40 | + | WriteLn(f); // Gibt 0.0 aus | |
| 41 | + | ``` | |
| 42 | + | ||
| 43 | + | ## Siehe auch: | |
| 44 | + | ||
| 45 | + | - [[Str/de|Str]] - Numerischen wert in String konvertieren. | |
| 46 | + | ||
| 47 | + | Autor: Mathias | |
| 48 | + | ||
| 49 | + | --- | |
| 50 | + | *From the Free Pascal wiki, page "Val/de", as it stood on 2020-01-16 after a change by Bart, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* | |
| 51 | + | Category: Pascal |
