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.
Resultado sin redondear
-
- Mensajes: 88
- Registrado: Vie Jul 28, 2006 9:36 am
Resultado sin redondear
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.
> 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.
Resultado sin redondear
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
Resultado sin redondear
Aprecio su tiempo, ya hice pruebas y quedo a la primera.
Gracias
Gracias