Programación General > Delphi
Edit!!
(1/1)
Katheryne:
Hola a todos,
Tengo un pequeño problemita, pues el caso es que quisiera mostrar en un edit un campo auto calculado de una tabla, y me lo muestra.
El problema radica en que me muestra el resultado completo, es decir: 1.2567891
y necesitaria que me mostrara 1.27
Si alguien sabe que puedo hacer por favor que me diga, tengo un gran rollo con esto..
Gracias de Antemano...
Enko:
Usa la funcion RoundTo. Te lo copypasteo deste Delphi que esta muy claro, Casi al final tenes ejemplos.
--- Citar ---Rounds a floating-point value to a specified digit or power of ten using “Banker’s rounding”.
Unit
Math
Category
Arithmetic routines
Delphi syntax:
type TRoundToRange = -37..37;
function RoundTo(const AValue: Double; const ADigit: TRoundToRange): Double;
Description
Call RoundTo to round AValue to a specified power of ten.
AValue is the value to round.
ADigit indicates the power of ten to which you want AValue rounded. It can be any value from –37 to 37 (inclusive).
RoundTo uses “Banker’s Rounding” to determine how to round values that are exactly midway between the two values that have the desired number of significant digits. This method rounds to an even number in the case that AValue is not nearer to either value.
The following examples illustrate the use of RoundTo:
Expression Value
RoundTo(1234567, 3) 1234000
RoundTo(1.234, -2) 1.23
RoundTo(1.235, -2) 1.24
RoundTo(1.245, -2) 1.24
Note: The behavior of RoundTo can be affected by the Set8087CW procedure or SetRoundMode function.
--- Fin de la cita ---
Un ejemplo para tu caso:
FloatNumber es cualquier numero en coma flotante.
--- Código: Text --- //No olvides agruegar a uses la unidad math.uses Math, etc...;...Edit1.Text := FloatToStr(RoundTo(FloatNumer, -2));
Navegación
Ir a la versión completa