2

I have the following expression in one of my textbox in my SSRS Report:

=IIF(IsNothing(Lookup(Trim(Fields!venta_Cod_vendedor.Value) & "-" & ReportItems!Textbox233.Value, Fields!AgregarVentas.Value, Fields!venta_prom_sem.Value, "EfectividadDeFrecuencias_Ventas")) = True

,"0"

,IIF(Lookup(Trim(Fields!venta_Cod_vendedor.Value) & "-" & ReportItems!Textbox233.Value, Fields!Agregar.Value, Fields!total_cant_pos.Value, "EfectividadDeFrecuencias_Total") <> "0"

,FormatNumber(Lookup(Trim(Fields!venta_Cod_vendedor.Value) & "-" & ReportItems!Textbox233.Value, Fields!AgregarVentas.Value, Fields!venta_frecuencia.Value, "EfectividadDeFrecuencias_Ventas")
/ Lookup(Trim(Fields!venta_Cod_vendedor.Value) & "-" & ReportItems!Textbox233.Value, Fields!Agregar.Value, Fields!total_cant_pos.Value, "EfectividadDeFrecuencias_Total"),2)

,"0"))

That division will give me an int64 number, 15 digits (If such math operation gives that amount of decimal digits).

So the results are:

enter image description here

Now here is the tricky part: My code behind that grabs the Dataset does a round and converts to decimal and then shows to a Crystal Report.

dr.venta_prom_sem = (Convert.ToDouble(dr.total_cant_pos) != 0 ? (Math.Round((Convert.ToDouble(dr.venta_frecuencia) / Convert.ToDouble(dr.total_cant_pos)), 2)).ToString() : "0");

So this will give me:

enter image description here

as you can see if I use a format Number the 1.3 will convert to 1,30 and that will be wrong, same as 1 (1,00). Now 1,339...etc will give me 1,34 and that is fine.

But check the 1.065, with FormatNumber that will give me 1.07 instead of 1.06.

So the thing is, how can I format my numbers to be the last non zero digit after the decimal point AND select the lower value if the (in this case) 3rd value is 5, instead of 1.07 be 1.06. I think If I use Ceiling or Floor it gives me the integer part.

Pedram
  • 6,256
  • 10
  • 65
  • 87
Nickso
  • 785
  • 1
  • 10
  • 32
  • Multiply the number by 100, use floor then divide by 100? – Scott Craner Oct 23 '15 at 16:17
  • Really good!, except the 1,339 etc will give me 1.33 and not 1.34 – Nickso Oct 23 '15 at 16:28
  • At what point do you want to go up? Normaly the demarcation is ,005, do you want ,0051 or ,006? – Scott Craner Oct 23 '15 at 16:31
  • Well If I grab Floor(1.33913043478261 * 100) / 100 will give me 1.33 and not 1.34 maybe using some sort of expression that round the number up? So far I have: `Floor(Lookup(Trim(Fields!venta_Cod_vendedor.Value) & "-" & ReportItems!Textbox221.Value, Fields!AgregarVentas.Value, Fields!venta_frecuencia.Value, "EfectividadDeFrecuencias_Ventas") / Lookup(Trim(Fields!venta_Cod_vendedor.Value) & "-" & ReportItems!Textbox221.Value, Fields!Agregar.Value, Fields!total_cant_pos.Value, "EfectividadDeFrecuencias_Total") * 100) / 100` – Nickso Oct 23 '15 at 16:42

1 Answers1

2

Try this:

=ROUND(1.339,2,MidpointRounding.ToEven)

This gives: 1.34

And

=ROUND(1.065,2,MidpointRounding.ToEven)

Gives: 1.06

Let me know if this was helpful.

alejandro zuleta
  • 13,962
  • 3
  • 28
  • 48