Page 1 of 1
picture get, transform y round
Posted: Thu Apr 30, 2015 3:52 pm
by fgondi
Estimados amigos,
Necesito formular _ get's numéricos a 2 decimales.
Hasta aquí no hay problema, si introduzco en el campo "oGet:cText()" un valor con mas decimales de los que refleja el picture, el dato se muestra redondeado.
oGet:cText( 111.120 ) --> 111.12
oGet:cText( 111.124 ) --> 111.12
oGet:cText( 111.125 ) --> 111.13
El problema es que ahora necesito que se redondee una posición hacia arriba, si el resto de decimales es mayor de cero.
oGet:cText( 111.120 ) --> 111.12
oGet:cText( 111.124 ) --> 111.13
oGet:cText( 111.125 ) --> 111.13
Re: picture get, transform y round
Posted: Thu Apr 30, 2015 3:58 pm
by FiveWiDi
Prueba en el VALID sumar 0.005
Es una idea, aunque el valor quedará alterado.
Re: picture get, transform y round
Posted: Thu Apr 30, 2015 4:09 pm
by fgondi
Muchas gracias por la respuesta,
El problema es que sólo quiero cambiar el valor de presentación. El valor del campo necesito que siga siendo el mismo
Re: picture get, transform y round
Posted: Thu Apr 30, 2015 4:13 pm
by D.Fernandez
Hola, la libreria ft_roud() de Nanfor.lib te puede servir. Esta en Harbour y xHarbour
Saludos
Ruben Dario Fernandez
Code: Select all
FT_ROUND()
Rounds a number to a specific place
Syntax
FT_ROUND( <nNumber> [, <nRoundToAmount> ;
[, <cRoundType> [, <cRoundDirection> ;
[, <nAcceptableError> ] ] ] ] ) -> nNumber
Arguments
<nNumber> is the number to round
<nRoundToAmount> is the fraction to round to or the number of places,
default is 2.
<cRoundType> is the type of rounding desired
"D" for Decimal (3 for thousandth, 1/1000) (default)
"F" for Fraction (3 for thirds, 1/3)
"W" for Whole numbers (3 for thousand, 1000)
<cRoundDirection> is the direction to round the number toward
"U" to round Up 1.31 -> 1.4
-1.31 -> -1.4
"D" to round Down 1.36 -> 1.3
-1.36 -> -1.3
"N" to round Normal 1.5 -> 2
-1.5 -> -2
1.49 -> 1
-1.49 -> -1
<nAcceptableError> is the amount that is considered acceptable
to be within, i.e., if you're within this amount of the number
you don't need to round
Returns
The number, rounded as specified.
Description
This function will allow you to round a number. The following can
be specified:
a. Direction (up, down or normal - normal is 4/5 convention)
b. Type (whole, decimal, fraction)
c. Amount (100's, 5 decimals, 16th, etc.)
Examples
// round normal to 2 decimal places
nDollars := FT_ROUND(nDollars)
// round normal to 6 decimal places
nIntRate := FT_ROUND(nIntRate, 6)
// round to nearest thousands
nPrice := FT_ROUND(nPrice, 3, NEAREST_WHOLE_NUMBER)
// round Up to nearest third
nAmount := FT_ROUND(nAmount, 3, NEAREST_FRACTION, ROUND_UP)
// round down to 3 decimals Within .005
nAvg := FT_ROUND(nAvg, 3, , ROUND_DOWN, .005)
Re: picture get, transform y round
Posted: Thu Apr 30, 2015 4:31 pm
by fgondi
Muchas gracias Rubén,
La función puede hacer los cálculos exactamente como lo necesito.
Pero como se lo aplico a los pictures de los get's
Re: picture get, transform y round
Posted: Thu Apr 30, 2015 6:35 pm
by D.Fernandez
Una locura perooo, quizas duplicando las variables.
nUno := 111.143
nUnoAMostrar := FT_Roud(nUno,......)
Queda feo pero..
Saludos
Ruben Dario Fernandez
Re: picture get, transform y round
Posted: Fri May 01, 2015 6:19 pm
by fgondi
Muchas gracias a todos,
Al final he cambiado la clase TClipGet que llama a la clase Get de Harbour.
He añadido 2 métodos y una variable:
Que define el número de decimales a redondear
He modificado los métodos PutMask y unTransform que se encargan de la presentación en pantalla.
Code: Select all
METHOD PutMask( xValue, lEdit ) Class TClipGet
local nSalto, xValue2
if ::GHE_nDecimal<>-1 .and. Valtype(xValue)='N'
nSalto := 4 / ( 10^(::GHE_nDecimal+1) )
xValue := xValue+nSalto
endif
return ::Super:PutMask( xValue, lEdit )
METHOD unTransform() Class TClipGet
local xValue, nSalto
xValue := ::Super:unTransform()
if ::GHE_nDecimal<>-1 .and. Valtype(xValue)='N' .and. Valtype(::Original)='N'
nSalto := 4 / ( 10^(::GHE_nDecimal+1) )
if ::VarGet()+nSalto == xValue .or. Round(::VarGet()+nSalto, ::GHE_nDecimal)==xValue
xValue := ::VarGet()
else
xValue := xValue-nSalto
endif
endif
return xValue
De momento y con la pruebas que he realizado funciona.
Seguiré haciendo pruebas, para saber si funciona bien o si tendré algún problema.