Resultado sin redondear

Foro público de Xailer en español
Responder
gaboais
Mensajes: 35
Registrado: Vie May 21, 2010 2:09 am

Resultado sin redondear

Mensaje por gaboais »

HOLA BUEN DIA,..
TENGO UN PROBLEMA :
COMO PUEDO TRUNCAR UNA CANTIDAD, O SEA,..
SI TENGO LA OPERACION DE ( 5 / 3 ) = 1.66
ME ARROJA EL RESULTADO REDONDEADO = 1.67
Y LO QUE DESEO ES EL RESULTADO SIN REDONDEAR = 1.66
GRACIAS POR SUS CONOCIMIENTOS Y TIEMPO.
GABRIEL GONZALEZ A.
Carlos Mora
Mensajes: 88
Registrado: Vie Jul 28, 2006 9:36 am

Resultado sin redondear

Mensaje por Carlos Mora »

Hola Gabriel,
> COMO PUEDO TRUNCAR UNA CANTIDAD, O SEA,..
> SI TENGO LA OPERACION DE ( 5 / 3 ) = 1.66
> ME ARROJA EL RESULTADO REDONDEADO = 1.67
> Y LO QUE DESEO ES EL RESULTADO SIN REDONDEAR = 1.66
En general [x]Harbour no redondea, mantiene la representación interna
como float, solo que al 'traducir' el float a una representación legible
lo muestra con los decimales que le indique el picture, el SET_DECIMALS,
etc.
Tal vez se podrí­an dar más precisiones si pusieses un poco del código
para contextualizar la respuesta. Si es algo que admita un PICTURE,
prueba con PICTURE '999.99999999999999999999999999' o algo así­.
Un saludo
Carlos.
vgest
Mensajes: 32
Registrado: Lun Jul 30, 2012 5:06 pm

Resultado sin redondear

Mensaje por vgest »


Simplemente, nultiplica por 100 (o los decimales que quieras), toma la parte entera y vuelve a dividir por 100. Ejemplo:
int(((5/3) * 100) )/100 --> 1.66
Un saludo
gaboais
Mensajes: 35
Registrado: Vie May 21, 2010 2:09 am

Resultado sin redondear

Mensaje por gaboais »

Aprecio su tiempo, ya hice pruebas y quedo a la primera.
Gracias
Responder