Post Reply 
The "format" command
03-18-2016, 12:59 PM
Post: #1
The "format" command
I hope this doesn't turn out to be a "RTFM" style response. I'm new to prime (but love it) and am a die hard HP calculator user with well over 30 years of use under my belt. I've thus far written some nice little calculator program utilities on the PRIME, and have been exploring MSGBOX and INPUT without any problems.

The calculator firmware is up to date. Its a "A" revision hardware model using software build 8151.

But... I'm stumbling on the "format" program command and I can't find any reference to it in the forum.

EXPORT FormatTest()
BEGIN
LOCAL s;
s := format( 9.345, "s3" );
MSGBOX( s );
END;

I'd expect to get "9.34" in the msgbox output. Instead I get a msgbox output stating...

"format(9.345,s3 )
Error: Bad Argument Value"

The program won't compile if I use "FORMAT" and the case of the "S3" string doesn't make any difference".

Does anyone have any idea what I'm doing wrong or if the format command even works?
Find all posts by this user
Quote this message in a reply
03-18-2016, 02:57 PM
Post: #2
RE: The "format" command
format is a CAS command while a PPL program is essentially executed in Home mode, so you have some adjustments to do.
You can refer to this excellent tutorial: HP Prime CAS programming

In your case the trick is to build a string with the parameters you want to pass to format:
Code:
EXPORT FormatTest()
BEGIN
LOCAL s;
s:="9.3456," + STRING("s3");
s:=CAS.format( s );
MSGBOX( s );
END;

Or you can use STRING instead of format:
Code:
EXPORT StringTest()
BEGIN
LOCAL s;
s:=STRING(9.3456,5,2);
MSGBOX( s );
END;
Find all posts by this user
Quote this message in a reply
03-18-2016, 03:54 PM
Post: #3
RE: The "format" command
Thank you Didier, your comments were tremendously helpful. I shall have a look at the CAS programming primer you mentioned, as the difference between the two had (up till now) escaped me.

Thanks again - it was a big help

Ciaran
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: