• Martes 14 de Mayo de 2024, 23:08

Autor Tema:  Edit!!  (Leído 1310 veces)

Katheryne

  • Nuevo Miembro
  • *
  • Mensajes: 4
    • Ver Perfil
Edit!!
« en: Martes 1 de Marzo de 2005, 19:15 »
0
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

  • Miembro de PLATA
  • *****
  • Mensajes: 1562
  • Nacionalidad: 00
    • Ver Perfil
Re: Edit!!
« Respuesta #1 en: Miércoles 2 de Marzo de 2005, 02:13 »
0
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.
Un ejemplo para tu caso:
FloatNumber es cualquier numero en coma flotante.
Código: Text
  1.  
  2. //No olvides agruegar a uses la unidad math.
  3. uses Math, etc...;
  4. ...
  5. Edit1.Text := FloatToStr(RoundTo(FloatNumer, -2));
  6.  
  7.