Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/01/2005, 15:46
RAVENET
 
Fecha de Ingreso: enero-2005
Mensajes: 3
Antigüedad: 19 años, 3 meses
Puntos: 0
Exclamación Hola, ayudenme a utilizar esta inst. jscript. basic

Este es el codigo en el cual necesito que todos los resultados se muestren con dos decimales.. creo que es con tostring... pero no sé como usarlo,,, ayudenme por favor...





<SCRIPT language=JavaScript>
<!--
function calculo2 (num) {
if (num <=2)
(document.f1.res.value =74.75)
if (num >2 && num <=20)
(document.f1.res.value =(((num-2)*5.5)+65)*(.15)+(((num-2)*5.5)+65))
if (num >20 && num <=100)
(document.f1.res.value =(((num-2)*5)+74)*(.15)+(((num-2)*5)+74))
if (num >100 && num <=200)
(document.f1.res.value =(((num-2)*4.5)+123)*(.15)+(((num-2)*4.5)+123))
if (num >200)
(document.f1.res.value =(((num-2)*4)+222)*(.15)+(((num-2)*4)+222))
}
//-->

</SCRIPT>

MIREN.. ESTE ES EL CODIGO QUE NECESITO INCRUSTAR (TO.STRING) PERO NO SE COMO PONERLO EN EL CODIGO DE ARRIBA.. OJALA PUEDAN ECHARME LA MANO.

<SCRIPT LANGUAGE=JSCRIPT RUNAT=SERVER>

function CALCULO(sender:Object, e:EventArgs):void

{

AREA.Text = BASE1.Text * ALTURA.Text / 2;

// formateando la salida

AREA.Text = Double.Parse(AREA.Text).ToString("#.##");
}

</script>




Al final ya cargado el resultado (AREA), se esta realizando una operación extra, es decir se esta formateando, lo que se pretende es que solo aparezcan dos decimales en la salida, como se obserava del ejemplo primero el AREA.TEXT se convierte a DOUBLE y como tal ya puede usar la instrucción ToString(string de formato), esta string de formato puede contener los siguientes caracteres:


Format character
Name
Description

0
Zero placeholder
If the value being formatted has a digit in the position where the '0' appears in the format string, then that digit is copied to the output string. The position of the leftmost '0' before the decimal point and the rightmost '0' after the decimal point determines the range of digits that are always present in the output string.

#
Digit placeholder
If the value being formatted has a digit in the position where the '#' appears in the format string, then that digit is copied to the output string. Otherwise, nothing is stored in that position in the output string. Note that this specifier never displays the '0' character if it is not a significant digit, even if '0' is the only digit in the string. It will display the '0' character if it is a significant digit in the number being displayed.

.
Decimal point
The first '.' character in the format string determines the location of the decimal separator in the formatted value; any additional '.' characters are ignored. The actual character used as the decimal separator is determined by the NumberDecimalSeparator property of the NumberFormatInfo object that controls formatting.