La Web del Programador: Comunidad de Programadores
https://www.lawebdelprogramador.com/foros/Delphi/1164424-funcion-round-en-delphi.html

funcion round en delphi

funcion round en delphi

Publicado por pablo (25 intervenciones) el 01/12/2009 21:00:43
hola a todos!!
les hago una consulta.
mi procedimiento de botton click es:

edit3.text := floattostr (
strtofloat(edit1.text) /
strtofloat(edit2.text));

este procedimiento me devuelve el resultado en numero real y yo quiero que me lo devuelva en el entero mas cercano a la fraccion, creo que podria usar la funcion round, pero como lo podria aplicar en mi ejemplo?
desde ya muchas gracias.

RE:funcion round en delphi

Publicado por Eva (484 intervenciones) el 01/12/2009 21:12:38
Returns the value of X rounded to the nearest whole number.

Unit

System

Category

arithmetic routines

Delphi syntax:

function Round(X: Extended): Int64;

Description

In Delphi, the Round function rounds a real-type value to an integer-type value.

X is a real-type expression. Round returns an Int64 value that is the value of X rounded to the nearest whole number. If X is exactly halfway between two whole numbers, the result is always the even number. This method of rounding is often called "Banker’s Rounding".

If the rounded value of X is not within the Int64 range, a runtime error is generated, which can be handled using the EInvalidOp exception.

Note: The behavior of Round can be affected by the Set8087CW procedure or SetRoundMode function.

......

Con Round te lo redondea, si solo quieres la parte entera usa la función Int

Returns the integer part of a real number.

Unit

System

Category

arithmetic routines

Delphi syntax:

function Int(X: Extended): Extended;

Description

In Delphi code, Int returns the integer part of X; that is, X rounded toward zero. X is a real-type expression.

......

y si lolo quieres la parte decimal usa la función frac

Returns the fractional part of a real number.

Unit

System

Category

arithmetic routines

Delphi syntax:

function Frac(X: Extended): Extended;

Description

In Delphi code, the Frac function returns the fractional part of the argument X.

X is a real-type expression. The result is the fractional part of X; that is, Frac(X) = X - Int(X).