Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
Philippe Nomail webforumsuser
En Flash MX 2004 - d'après les sources de mx.data.formatters.NumberFormatter et avec les commentaires buggés ;-)
function format(value:Number, precision:Number):String { var strValue:String; if( precision > 0 ) { var perc:Number = Math.pow( 10, precision ); strValue = ( Math.round( value * perc ) / perc ).toString(); // check to be sure that we have the correct format if( strValue.length > 0 ) { var index = strValue.lastIndexOf( '.' ); var zCnt = 0; if( index < 0 ) { strValue += "."; zCnt = precision; } else zCnt = this.precision -( strValue.length- ( index +1 )); // add the zeros on strValue = strValue + "0000000000000000000000000000".substring( 0, zCnt ); } // if } else strValue = Math.round( value ).toString(); // trunc to 0 percision
return strValue; }
var a = 12.14785;
trace(" format 0 = "+format(a,0)); trace(" format 1 = "+format(a,1)); trace(" format 2 = "+format(a,2)); trace(" format 3 = "+format(a,3));
Philippe http://philflash.inway.fr
En Flash MX 2004 - d'après les sources de mx.data.formatters.NumberFormatter
et avec les commentaires buggés ;-)
function format(value:Number, precision:Number):String {
var strValue:String;
if( precision > 0 ) {
var perc:Number = Math.pow( 10, precision );
strValue = ( Math.round( value * perc ) / perc ).toString();
// check to be sure that we have the correct format
if( strValue.length > 0 ) {
var index = strValue.lastIndexOf( '.' );
var zCnt = 0;
if( index < 0 ) {
strValue += ".";
zCnt = precision;
}
else
zCnt = this.precision -( strValue.length- ( index +1 ));
// add the zeros on
strValue = strValue + "0000000000000000000000000000".substring( 0, zCnt );
} // if
}
else
strValue = Math.round( value ).toString(); // trunc to 0 percision
return strValue;
}
var a = 12.14785;
trace(" format 0 = "+format(a,0));
trace(" format 1 = "+format(a,1));
trace(" format 2 = "+format(a,2));
trace(" format 3 = "+format(a,3));
En Flash MX 2004 - d'après les sources de mx.data.formatters.NumberFormatter et avec les commentaires buggés ;-)
function format(value:Number, precision:Number):String { var strValue:String; if( precision > 0 ) { var perc:Number = Math.pow( 10, precision ); strValue = ( Math.round( value * perc ) / perc ).toString(); // check to be sure that we have the correct format if( strValue.length > 0 ) { var index = strValue.lastIndexOf( '.' ); var zCnt = 0; if( index < 0 ) { strValue += "."; zCnt = precision; } else zCnt = this.precision -( strValue.length- ( index +1 )); // add the zeros on strValue = strValue + "0000000000000000000000000000".substring( 0, zCnt ); } // if } else strValue = Math.round( value ).toString(); // trunc to 0 percision
return strValue; }
var a = 12.14785;
trace(" format 0 = "+format(a,0)); trace(" format 1 = "+format(a,1)); trace(" format 2 = "+format(a,2)); trace(" format 3 = "+format(a,3));
Philippe http://philflash.inway.fr
David The Dolphin
MonNombre = Math.round(MonAncienNombre*100)/100
-- DTD --- Quand j'étais jeune, j'étais con. Je suis resté très jeune. (JC. Van Damme) ----
"Iam Noone" a écrit dans le message de news:bqft7i$1a5$
Bonjour à tous, Comment afficher une valeur avec x décimales ? Exemple : 12,14785 donne 12,15 ? Merci !
MonNombre = Math.round(MonAncienNombre*100)/100
--
DTD
---
Quand j'étais jeune, j'étais con. Je suis resté très jeune. (JC. Van Damme)
----
"Iam Noone" <iam.noone@caramail.com> a écrit dans le message de
news:bqft7i$1a5$1@forums.macromedia.com...
Bonjour à tous,
Comment afficher une valeur avec x décimales ?
Exemple : 12,14785 donne 12,15 ?
Merci !