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

Title: Can't parse an Integer with FmtInt in STRPRINT?
Post 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?
Title: Re: Can't parse an Integer with FmtInt in STRPRINT?
Post by: b_carlton on July 14, 2021, 10:47:13 AM
You might want to use MOD 100 first to isolate the last two digits.
Title: Re: Can't parse an Integer with FmtInt in STRPRINT?
Post by: Bolt on July 14, 2021, 10:59:01 AM
Thanks Bernie, I got so focused on strings in forgot about simple math...
Title: Re: Can't parse an Integer with FmtInt in STRPRINT?
Post by: franji1 on July 14, 2021, 11:13:56 AM
If you want 102 to display as 02, don't forget to set the Justification parameter in FmtInt to ZeroPad.
Title: Re: Can't parse an Integer with FmtInt in STRPRINT?
Post by: Bolt on July 14, 2021, 11:27:55 AM
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?
Title: Re: Can't parse an Integer with FmtInt in STRPRINT?
Post by: franji1 on July 14, 2021, 11:50:08 AM
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?)