picture get, transform y round

picture get, transform y round

Postby fgondi » Thu Apr 30, 2015 3:52 pm

Estimados amigos,

Necesito formular los campos 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
Un saludo
Fernando González Diez
ALSIS Sistemas Informáticos
User avatar
fgondi
 
Posts: 694
Joined: Fri Oct 07, 2005 6:58 am
Location: Palencia, España

Re: picture get, transform y round

Postby FiveWiDi » Thu Apr 30, 2015 3:58 pm

Prueba en el VALID sumar 0.005

Es una idea, aunque el valor quedará alterado.
Un Saludo
Carlos G.

FiveWin 24.02 + Harbour 3.2.0dev (r2403071241), BCC 7.7 Windows 10
FiveWiDi
 
Posts: 1068
Joined: Mon Oct 10, 2005 2:38 pm

Re: picture get, transform y round

Postby fgondi » Thu Apr 30, 2015 4:09 pm

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
Un saludo
Fernando González Diez
ALSIS Sistemas Informáticos
User avatar
fgondi
 
Posts: 694
Joined: Fri Oct 07, 2005 6:58 am
Location: Palencia, España

Re: picture get, transform y round

Postby D.Fernandez » Thu Apr 30, 2015 4:13 pm

Hola, la libreria ft_roud() de Nanfor.lib te puede servir. Esta en Harbour y xHarbour

Saludos

Ruben Dario Fernandez
Code: Select all  Expand view
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)
Dario Fernandez
FWH 22.12, Harbour, MVS2022 Community, BCC, MySql & MariaDB, Dbf/Cdx VSCode.
Maldonado - Uruguay
D.Fernandez
 
Posts: 455
Joined: Wed Jul 31, 2013 1:14 pm
Location: Maldonado - Uruguay

Re: picture get, transform y round

Postby fgondi » Thu Apr 30, 2015 4:31 pm

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
Un saludo
Fernando González Diez
ALSIS Sistemas Informáticos
User avatar
fgondi
 
Posts: 694
Joined: Fri Oct 07, 2005 6:58 am
Location: Palencia, España

Re: picture get, transform y round

Postby D.Fernandez » Thu Apr 30, 2015 6:35 pm

Una locura perooo, quizas duplicando las variables.

nUno := 111.143
nUnoAMostrar := FT_Roud(nUno,......)

Queda feo pero..

Saludos
Ruben Dario Fernandez
Dario Fernandez
FWH 22.12, Harbour, MVS2022 Community, BCC, MySql & MariaDB, Dbf/Cdx VSCode.
Maldonado - Uruguay
D.Fernandez
 
Posts: 455
Joined: Wed Jul 31, 2013 1:14 pm
Location: Maldonado - Uruguay

Re: picture get, transform y round

Postby fgondi » Fri May 01, 2015 6:19 pm

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:

Code: Select all  Expand view
Data Ghe_nDecimal init -1
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  Expand view
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.
Un saludo
Fernando González Diez
ALSIS Sistemas Informáticos
User avatar
fgondi
 
Posts: 694
Joined: Fri Oct 07, 2005 6:58 am
Location: Palencia, España


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 13 guests