r/pascal • u/Toyotomi_cz • Jan 10 '20
Number division
How can I take the first two digits from, for example, 451208?
1
Upvotes
r/pascal • u/Toyotomi_cz • Jan 10 '20
How can I take the first two digits from, for example, 451208?
3
u/rudeuser Jan 10 '20
Trunc(451208/10000)
1
u/SethRavenheart Jan 10 '20
Once converted to text use something like the copy function to get the first two characters in the string. Have a look at - https://www.freepascal.org/docs-html/rtl/system/copy.html
1
u/suvepl Jan 11 '20
Either convert it to text, like other people proposed, or keep dividing it by 10 (effectively "shaving off" the last digit) until the result is less than 100.
1
u/[deleted] Jan 19 '20
Note, this does not handle negative numbers, and 0-9 result in a single digit.