Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to set constraints to my parameters, e.g., "m", but Mma gives nonsensical output. How could I avoid this phenomenon by using another but "equivalent expression"? Or, is this just in my computer (i.e. a non-reproducible problem)?

case 1. output is as expected:

ToExpression[
 ToString[2.] <> ToString[">"] <> ToString["m"] <> ">=" <> 
  ToString[1.]]
2. > m >= 1.

case 2. output is unexpected:

ToExpression[
 ToString[0.10465923419974825] <> ToString[">"] <> ToString["m"] <> 
  ">=" <> ToString[-6.0857416503171394*^-6]]
-60.8574
share|improve this question
1  
The ToString[-6.0857416503171394*^-6] is problematic. (-6.08574 * 10 == -60.8574) Use Row[] or StringForm[]. –  J. M. Apr 10 '13 at 12:42
1  
But, maybe you'd like to use Inequality instead: (#1 > m >= #2) &[0.10465923419974825, -6.0857416503171394*^-6] –  J. M. Apr 10 '13 at 12:51

1 Answer 1

The documentation says:

ToString[expr] gives a string corresponding to the printed form of expr in OutputForm.

The problem is with the OutputForm string of the exponent in the number:

ToString[-6.0857416503171394*^-6]
           -6
-6.08574 10

You can specify InputForm in this conversion with the second argument of ToString:

ToExpression[
 ToString[0.10465923419974825] <> ">" <> "m" <> ">=" <> 
  ToString[-6.0857416503171394*^-6, InputForm]
]
0.104659 > m >= -6.08574*10^-6

Note that you do not need ToString around things that are explicitly Strings.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.