FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour picture get, transform y round
Posts: 694
Joined: Fri Oct 07, 2005 06:58 AM
picture get, transform y round
Posted: Thu Apr 30, 2015 03: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
Posts: 1446
Joined: Mon Oct 10, 2005 02:38 PM
Re: picture get, transform y round
Posted: Thu Apr 30, 2015 03:58 PM

Prueba en el VALID sumar 0.005

Es una idea, aunque el valor quedará alterado.

Un Saludo

Carlos G.



FiveWin 25.12 + Harbour 3.2.0dev (r2502110321), BCC 7.7 Windows 11 Home

Posts: 694
Joined: Fri Oct 07, 2005 06:58 AM
Re: picture get, transform y round
Posted: Thu Apr 30, 2015 04: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
Posts: 555
Joined: Wed Jul 31, 2013 01:14 PM
Re: picture get, transform y round
Posted: Thu Apr 30, 2015 04:13 PM
Hola, la libreria ft_roud() de Nanfor.lib te puede servir. Esta en Harbour y xHarbour

Saludos

Ruben Dario Fernandez
Code (fw): Select all Collapse
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 2501, Harbour, MVS2022 Community, MySql & MariaDB, Dbf/Cdx VSCode.

Maldonado - Uruguay
Posts: 694
Joined: Fri Oct 07, 2005 06:58 AM
Re: picture get, transform y round
Posted: Thu Apr 30, 2015 04: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
Posts: 555
Joined: Wed Jul 31, 2013 01:14 PM
Re: picture get, transform y round
Posted: Thu Apr 30, 2015 06: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 2501, Harbour, MVS2022 Community, MySql & MariaDB, Dbf/Cdx VSCode.

Maldonado - Uruguay
Posts: 694
Joined: Fri Oct 07, 2005 06:58 AM
Re: picture get, transform y round
Posted: Fri May 01, 2015 06: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 (fw): Select all Collapse
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 (fw): Select all Collapse
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

Continue the discussion