Message Boards Message Boards

0
|
8581 Views
|
10 Replies
|
1 Total Likes
View groups...
Share
Share this post:
GROUPS:

Undesired parenthesis

Hello,

Please, take a look at following command:

Print[Framed["v =" NumberForm[Quantity[10.38, ("Meters")/("Seconds")], 2]]]

The output shows an undesired pair of parenthesis wrapping the right hand side of the equation. Does anyone knows how to get rid of them?

Anderson

Attachments:
10 Replies

This was really something! Thanks.

If you are fastidious about the proper math formating (fonts and spacings), try this:

Print[Framed[ DisplayForm@ FormBox[RowBox[{"v", "=", NumberForm[Quantity[10.38, ("Meters")/("Seconds")], 2]}], TraditionalForm]]]

I found out about FormBox by hitting the menu Cell > Show Expression.

POSTED BY: Gianluca Gorni

Thanks a lot. Nice solution. The use of Text can be very useful sometimes.

Did you miss the part "Also Text is not needed though to my eye it is useful for formatting"? It's there for a reason..

POSTED BY: Daniel Lichtblau

Perfect. Thanks a lot.

Thanks. Your solution is almost perfect, except by the lost of the output format.

You don't have to change the argument to NumberForm (did you try that)? Also Text is not needed though to my eye it is useful for formatting. The point of the response by @S.M.Blinder is that using Row is the correct way to go about this. The original code involves an implicit multiplication, and that causes the parens to be added.

For completeness, this could be done as:

Framed[Text[
  Row[{"v = ", 
    NumberForm[Quantity[10.38, ("Meters")/("Seconds")], 2]}]]]
POSTED BY: Daniel Lichtblau

Use the following instead:

Print[Framed[
  Row[{"v = ", 
    NumberForm[Quantity[10.38, ("Meters")/("Seconds")], 2]}]]]

The issue you were having was because "v=" NumberForm[...] means Times["v=",NumberForm[...]] and so the syntax form of the underlying quantity was taking over, because a string times a quantity doesn't evaluate. Another example of this would be:

"v=" RawBoxes@InterpretationBox[10, 10, SyntaxForm -> Mod]
POSTED BY: Nick Lariviere

Thanks for replying, but the argument of NumberForm function cannot be changed.

Framed[
 Text[Row[{"v = " , NumberForm[10.38, {4, 2}], " meters/second"}]]]
POSTED BY: S M Blinder
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract