I have typed out the following block of code in LaTex/SageTex.
\begin{sagesilent}
var('p1','p2')
q1 = 10 - 10*p1
q2 = 5 - 5*p2
B=1.4*q1+2*q2+0.5*q1*q2
\end{sagesilent}
B is $B=\sage{B}$.
The output is
B is B = 25.0000000000000 (p1 − 1.00000000000000)(p2 − 1)−14.0000000000000p1 − 10p2 + 24.0000000000000.
I would like for it to print out
B is B = 25 (p1 - 1)(p2 - 1)- 14p1 - 10p2 + 24.
I have looked through the Sagemath documentation without much luck. Apparently there is this method n() that takes a digit parameter and returns a truncated version of the expression. However, this returns a truncated version of the entire expression (which has no effect) not the floats that are in it.
I think that this question on ask.sagemath.org might be helpful, though you are right about applying it to the entire expression not being entirely straightforward. You could walk the expression tree and apply this but it's not so easy to do that either.