Host Engineering Forum
General Category => Do-more CPUs and Do-more Designer Software => Topic started by: Bolt on July 14, 2021, 10:30:28 AM
-
Is there a way I can take the last 2 digits from a number, and display it in STRPRINT? FmtInt(D0,dec,2) doesn't seem to do the trick, it will put all the digits in there.
I'm sure I can do it with STRPRINT, STRSUB, and then use STRPRINT again to use it in my longer string, but surely there's a way to do this all in one instruction?
-
You might want to use MOD 100 first to isolate the last two digits.
-
Thanks Bernie, I got so focused on strings in forgot about simple math...
-
If you want 102 to display as 02, don't forget to set the Justification parameter in FmtInt to ZeroPad.
-
If you want 102 to display as 02, don't forget to set the Justification parameter in FmtInt to ZeroPad.
Yes, I made sure to do that.
Still, shouldn't STRPRINT FmtInt(D0,dec,2,zeropad) take a longer number and only print the 2 digits, without first having to do MATH D0 = D1 % 100?
-
Still, shouldn't STRPRINT FmtInt(D0,dec,2,zeropad) take a longer number and only print the 2 digits, without first having to do MATH D0 = D1 % 100?
No. That is the minimal width, not maximum width. That's how most numeric- text formatting mechanisms work. If you want to truncate it, do you want the first 2 digits or the last 2 digits?
12345 (12 or 45?)