cancel
Showing results for 
Search instead for 
Did you mean: 
Jenab6
New member
4 2 0 0
Message 1 of 10
1,332
Flag Post

Syntax for the [format] command

HP Recommended
HP Prime

Sometimes, I want to present (on my HP Prime Terminal) output that differs in format from the format selected on my Home Settings. The HELP information on the "format" command, accessible in the HP Prime's catalog, suggests that this is the command by which this can be done.

 

But it doesn't work.

 

When I put this line of code in a PPL program:

 

PRINT(format(9.3456,"s3"));

 

I don't get 9.35, like it says I should in the HELP for the format command. Instead, I get this message (on my Terminal):

 

format(9.3456,s3)

 Error: Bad Argument Value

 

Obviously, either there's a bug in this command or I'm using the command wrong. Which is it, and how do I make the format command work as it is supposed to work?

0 Kudos
Tags (1)
9 REPLIES 9
Maké
Level 9
3,551 3,490 180 541
Message 2 of 10
Flag Post
HP Recommended

Hi!, @jenab6 :

 

See, this image of PRINT in program of User Guide, page 654 ...

PRINT.PNG

 

Kind Regards !.
Have a nice day !.
@Maké (Technical Advisor Premium - HP Program Top Contributor).
Provost in HP Spanish Public Forum ... https://h30467.www3.hp.com/
0 Kudos
Ciro_Bruno
Level 4
137 122 6 17
Message 3 of 10
Flag Post
HP Recommended

I've been trying this as well and I've got the same conclusion you have.

 

Let me add some info I've gathered through my test. There's no conclusion, its just a contribution, but maybe it can help someone figure it out.

 

1) The command "PRINT(format(9.3456,"s3"))" works fine in CAS. It outputs "9.35" in terminal screen.

 

2) This command doesn't work at all in Home mode. It shows the same message you've reported.

 

3) It doesn't also inside a program. I've tried to open a new CAS program and it doesn't work either.

 

Now I'm also wondering what's up.

 

Regards,

Ciro.

0 Kudos
Maké
Level 9
3,551 3,490 180 541
Message 4 of 10
Flag Post
HP Recommended

Hi!, @Jenab6 :

 

If you see, page 472, chapter 23 of User Guide, then ...

 

format :
Returns a real number as a string with the indicated format (f=float, s=scientific, e=engineering).
format(Real, String)

 

Example :
format(9.3456,"s3") returns "9.35"

 

Only run OK, if use CAS.

Kind Regards !.
Have a nice day !.
@Maké (Technical Advisor Premium - HP Program Top Contributor).
Provost in HP Spanish Public Forum ... https://h30467.www3.hp.com/
0 Kudos
cyrille
Level 6
Level 6
252 251 42 77
Message 5 of 10
Flag Post
HP Recommended

Hello,

 

This is due to the way that home and CAS interract and pass arguements.

 

Since not all CAS arguements can be "expressed" in home, you can pass arguments from Home to CAS as strings and at the moment when home calls Cas, these arguements will be "parsed"/"compiled"...

 

Thus, when you do : format(9.3456,"s3") from home, the moment Home tries to call CAS, it will try to compile the s3, which will result in an error.

 

You can solve this in 2 ways: telling home to not evaluate the string use: '"s3"' (note the extra ' of the quote function around the string). Or you can give a string which will compile into the string that you want: "\"s3\""

 

Cyrille

I am an HP Employee
Ciro_Bruno
Level 4
137 122 6 17
Message 6 of 10
Flag Post
HP Recommended

Fantastic, Cyrille.

 

I've tested and it has worked fine now, both in Home environment and through the program.

 

Your explanation is absolutelly clear and it will be usefull for many other circumstances.

 

Where have you learned about avoiding the Home to compile unwanted arguments? Has it been in the manual or is there any other source? Do you remember?

 

Thank you very much.

Regards,

Ciro.

0 Kudos
cyrille
Level 6
Level 6
252 251 42 77
Message 7 of 10
Flag Post
HP Recommended

Hello,

 

"Where have you learned about avoiding the Home to compile unwanted arguments?

Has it been in the manual or is there any other source?

Do you remember"

 

 

I might remember.... Codding it 🙂

I am one of the HP engineers that have created HP Prime, so, I am the one to blame for that type of (justifiable) idiosyncraties  🙂

 

I wrote a document that dives in these items a couple of years ago. It might need to be revised, but should be mostly still valid.

You can find it attached to this post in the HP calculator museum forums:

http://hpmuseum.org/forum/thread-6218-post-55671.html#pid55671

 

 

Happy reading

Cyrille

I am an HP Employee
Ciro_Bruno
Level 4
137 122 6 17
Message 8 of 10
Flag Post
HP Recommended

Hello Cyrille.

 

There's nothing to feel blamed for. I'm sorry, I didn't mean to embarrass you. I wasn't aware you're part of development team.

 

The document is very interresting. Timely I'm gonna try what's described in it.

 

I intend to make custom Apps based in HP Prime native Apps. Would you have similar docs regarding customizing apps or programming for App?

 

Thank you very much.

Regards,

Ciro.

0 Kudos
cyrille
Level 6
Level 6
252 251 42 77
Message 9 of 10
Flag Post
HP Recommended

Hello,

 

"There's nothing to feel blamed for. I wasn't aware you're part of development team."

 

Don't worry, this is more of a self blame...

 

Often, things seem that they should be very simple to do/create/make... But when it comes to implementation time, you discover that they are a lot of edge cases that were not obvious at first...

At this point, you need to make choices on how things need to work. And most of the time, these are choices between two "not perfect" options. As a result, you pick one (let's be honnest, usually the easiest to implement).

But you also end up causing problem for 50% of the population that would have rather you make the other choice...

 

"I intend to make custom Apps based in HP Prime native Apps. Would you have similar docs regarding customizing apps or programming for App?"

 

No, unfortunately.

The main advice there is to start by using the app template which you normally get when you edit an empty app program. This gives you a lot of the framework that you will need.

Also remember that you can override keys (in the program editor, press the MENU key and select create user key. And do not forget to put a #pragma to setup the compilation mode (comma, dot...) so that your program can work on any calcualtor

 

Cyrille

I am an HP Employee
Ciro_Bruno
Level 4
137 122 6 17
Message 10 of 10
Flag Post
HP Recommended

I understand.

 

This is a metter of development. During one step, it's possible to plan some steps ahead, but not all of them. Eventually the developer will have to face such decisions you've described. From time to time, it's necessary to step back, demolish many parts of it and rebuild them in order to make better room for the upcoming demands.

 

My suggestion is to always publish more details about the use of new implementations, as well as the past ones, as far as possible. Then you can spread this knowledge among users and we'll probably see some interresting portions of code shared in this forum. It's just a suggestion.

 

Thank you for your attention.

Congratulations to you, Tim and all the group for the fantastic product you deliver.

Best regards,

Ciro Bruno.

0 Kudos
† The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation