I have a mathematica file with an algorithm that feeds another program with data.
my problem is that some times (randomly) the output is in fraction instead of decimal. The other program (java) does not read fractions, so I have to feed it with decimal numbers.
One solution is to use the N[.] function before it output, but this is really painful procedure. Is there any setting in mathematica forcing it to return as output only decimals?

By the way, welcome to Mathematica.SE! Please consider registering your account, so that any votes you might get for this question are added to those received for future questions. As you gain reputation points, you will be able to do more things like participate in the chat room.
–
Verbeia♦Aug 1 '12 at 13:42

I have several algorithms, pretty big ones, and I was seeking for a general way to overcome my problem before getting inside the code and start messing with it. Thanx for the hint, i will do register.
–
VasilisAug 1 '12 at 13:54

You only need to use N at the very last stage before sending the output to Java.
–
Verbeia♦Aug 1 '12 at 14:06

1

Take @Verbeia 's advice on using real inputs seriously, specially if you have a long heavy weight algorithm. The difference in space and time it can make is enormous, and only generated by inputing, e.g, 2 instead of 2. or 2`
–
RojoAug 1 '12 at 19:02

Make sure all your input is in floating point (Real) form, not Integers or Rational. You might find this tutorial helpful. I am willing to bet that the cases where you get a fraction are not really random.

If wrapping your output in N is unacceptable to you for some reason, you could instead use a rule once you have your output: data /. x_Rational :> N@x. This will almost certainly be slower than N.

first of all thank you for your reply! I will check the tutorial u sent me. I was overexaggerating when i said randomly, but frankly, i give an initial input of 5 variables in my algorithm, and i get hundreds of outputs, and the percentage of getting fractions instead of decimal numbers is not greater than 1% based on my hundreds and hundreds of tests. nevertheless, once i get fraction, the second program is useless (java). The second solution you suggest seems to be similar to the N[.] function, with respect to the editing i have to do in my code. i was wondering if there was a setting hidden
–
VasilisAug 1 '12 at 13:59

As long as 1 value is MachinePrecision the output will be that too, isn't it?
–
Sjoerd C. de VriesAug 1 '12 at 14:53

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.