Sacado de xHarbour
Round()
Rounds a numeric value to a specified number of digits
Syntax
Round( <nNumber>, <nDecimals> ) --> nRounded
Arguments
<nNumber>
This is the numeric value to round.
<nDecimals>
If the parameter is a positive number, it specifies the number of decimal
places to retain after the decimal point. If specified as negative value,
Round() operates on the digits before the decimal point, thus rounding
integer numbers.
Return
The function returns the rounded numeric value.
Description
Round() is a numeric function used to round numbers to a given number of
decimal places. Digits 5 to 9 are rounded up, while digits 0 to 4 round
down.
Info
See also: Abs(), Int(), SET DECIMALS, SET FIXED, Str(), Val()
Category: Numeric functions
Source: rtlround.c
LIB: xhb.lib
DLL: xhbdll.dll
Example
// The example demonstrates results of Round() and how SET FIXED
// influences the display of rounded numbers.
PROCEDURE Main
SET DECIMALS TO 4
SET FIXED ON
? Round( 1234.5678, 0) // result: 1235.0000
? Round( 1234.5678, 1) // result: 1234.6000
? Round( 1234.5678, 2) // result: 1234.5700
? Round( 1234.5678, 3) // result: 1234.5680
? Round( 1234.5678,-1) // result: 1230.0000
? Round( 1234.5678,-2) // result: 1200.0000
? Round( 1234.5678,-3) // result: 1000.0000
SET FIXED OFF
? Round( 1234.5678, 0) // result: 1235
? Round( 1234.5678, 1) // result: 1234.6
? Round( 1234.5678, 2) // result: 1234.57
? Round( 1234.5678, 3) // result: 1234.568
? Round( 1234.5678,-1) // result: 1230
? Round( 1234.5678,-2) // result: 1200
? Round( 1234.5678,-3) // result: 1000
RETURN
------------------------------------------------------------ --------------------
Respecto a la longitud de la variable no suele haber problemas salvo que el
numero sea mayor que lo que cabe en el campo.
Si le sobran decimales los ignora (o redondea a los decimales que haya en el
campo, no lo se ahora).
Si le sobra parte entera, es un problema de overflow que no debes permitir
que llegue a grabarlo ya que te puede provocar un grave problema de
informacion- Lo normal es avisar al usuario de esta situacion.
"Lucas de Beltran" <
lucasdebeltran@gmail.com> escribió en el mensaje
news:4a97c896$[email=1@svctag-j7w3v3j....]1@svctag-j7w3v3j....[/email]
>
> Hola:
>
> Tengo una variable numérica cuya longitud es mayor que el campo de la base
> de datos.
>
> ¿Cómo se puede acortar?.
>
> ¿Y si quiero quitar unos decimales a la variable, cómo se hace?.
>
>
> Muchísimas gracias. Un saludo,
>
> Lucas