Jump to content
We've recently updated our Privacy Statement, available here ×

how to add two variables of type double?


mcancino

Recommended Posts

hello! 

 

I'm new to iReports, someone could help me, telling me how to add two variables of type double and store it in a third. 

and try this: $ {V} importe_sin_iva doubleValue () + $ V {} calculo_iva doubleValue ().. 

but the result is not correct, I expect an answer. 

 

greetings and thanks.

Link to comment
Share on other sites

  • Replies 10
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Can you clarify what does "the result is not correct" means, is the addition wrong, does it triggers an error, etc.

A couple of things to check:
- check that the 3rd variable the one you are assigning the result is also a double
- check the order of the variables in the report outline, variables are executed in the order they appear in the outline. So assuming the result is stored in $V{importe_con_iva}, if you have them in this order:
  - $V{importe_sin_iva} = $F{importe}  
  - $V{importe_con_iva} = $V{importe_sin_iva} + $V{calculo_iva}
  - $V{calculo_iva} =  $V{importe_sin_iva} * 0.21

the result will be wrong since by the time $V{importe_con_iva} is calculated $V{calculo_iva} is not yet defined. Makes sense?

Link to comment
Share on other sites

gracias por contestar,

 

te explico, tengo tres variables de tipo double,

- $V{importe_sin_iva}

- $V{calculo_iva}

- $V{total_iva}

en ese mis orden, quiero sumar el $V{importe_sin_iva} + $V{calculo_iva} = $V{total_iva}, pero no suma correctamente: 24,926.29 + 3,779.12 = 27,398.62 (es a lo que me refiero cuando el resultado no es correcto).}

 

saludos

 

Link to comment
Share on other sites

Following seems to be working. The result is 28705.41. Try setting values in InitialValueExpression.

    <variable name="Variable_1" class="java.lang.Double">
        <initialValueExpression><![CDATA[new Double(24926.29)]]></initialValueExpression>
    </variable>
    <variable name="Variable_2" class="java.lang.Double">
        <initialValueExpression><![CDATA[new Double( 3779.12)]]></initialValueExpression>
    </variable>
    <variable name="Variable_3" class="java.lang.Double">
        <initialValueExpression><![CDATA[$V{Variable_1} + $V{Variable_2}]]></initialValueExpression>
    </variable>

 

Link to comment
Share on other sites

hola, ya realice la prueba de establecer valores en InitialValueExpression, pero sigue mandando el mismo resultado (27,398.62).

 

así lo tengo:

 

$V{importe_sin_iva}*$P{%_iva}

new Double(3779.12)

$V{importe_sin_iva}+$V{calculo_iva}

$V{importe_sin_iva}+$V{calculo_iva}

$V{total_importe_nivel1}

new Double(24926.29)

Link to comment
Share on other sites

That's because you have the order wrong. You have to define total_iva last.

<variable name="calculo_iva" class="java.lang.Double" resetType="None">
<variableExpression><![CDATA[$V{importe_sin_iva}*$P{%_iva}]]></variableExpression>
<initialValueExpression><![CDATA[new Double(3779.12)]]></initialValueExpression>
</variable>
<variable name="importe_sin_iva" class="java.lang.Double" resetType="None">
<variableExpression><![CDATA[$V{total_importe_nivel1}]]></variableExpression>
<initialValueExpression><![CDATA[new Double(24926.29)]]></initialValueExpression>
</variable>
<variable name="total_iva" class="java.lang.Double" resetType="None">
<variableExpression><![CDATA[$V{importe_sin_iva}+$V{calculo_iva}]]></variableExpression>
<initialValueExpression><![CDATA[$V{importe_sin_iva}+$V{calculo_iva}]]></initialValueExpression>
</variable>

 

Link to comment
Share on other sites

muchas gracias!!! :) no sabia que afecta mucho el orden de las variables en el XML, ya quedo resuelto, muchas gracias, espero mas adelante poder tener su apoyo en iReport sobre otros detalles que me puedan salir.

gracias hozawa y marianol.

Link to comment
Share on other sites

Hola a todos!

alguno de ustedes me podria ayudar para exportar a PDF un archivo jrxml que cree en iReport, pero no lo exporta correctamente, explico los detalles:

1.- Se está creando un .jar para ejecutar la plantilla que se creó en iReports (Jaspersotf iReportDesigner 5.5.1), la fuente de datos se está tomando de un CSV para exportarlo a un PDF, todo esto esta creado en Windows 7, el motivo del .jar es que es multiplataforma y pensamos que sería los más útil, creyendo que no tendríamos ningún problema en ejecución ya sea en Linux, Mac o Windows. 

2.- El detalle  en Mac, ahí si se genera el PDF pero tenemos algunos detalles en el archivo.

●     El símbolo de $ lo cambia por este símbolo ¤.

●     En el texto, las palabras que tienen acentos por ejemplo: Alambrón le quita la letra ó y lo deja como Alambrn.

●     Cuando estamos trabajando con campos como precios e importes que manejan decimales y un rango de números donde se tiene que mostrar puntos, comas para la separación no lo muestra adecuadamente, ejemplo: 19,520,500.00 nos manda 19.520.500,00.

ya intente cambiando el encoding en XML <?xml version="1.0" encoding="ISO-8859-1"?>, pero sigue con el mismo problema, espero que alguien me pueda ayudar.

saludos y gracias.

Link to comment
Share on other sites

  • 4 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...