Autor Zpráva
larryonov
Profil *
Ahoj, mam tuhle funkci v js:


function fix( f ){
f = f.toString( );
var re = /\,/gi;
f = f.replace( re, "\." );

f = Math.round( f * 100 );
f = f.toString( );
var sMinus = f.slice( 0, 1 );
if( sMinus == '-' ){
f = f.slice( 1, f.length )
}
else
sMinus = '';
if( f.length < 3 ) {
while( f.length < 3 )
f = '0' + f;
}

var w = sMinus + f.slice( 0, f.length-2 ) + "." + f.slice( f.length-2, f.length );

var poprawnyFloat = /^-?[0-9]{1,}[.]{1}[0-9]{1,}$/i;

if( w.search( poprawnyFloat ) == -1 )
w = '0.00';
return w;
}


ta funkce zasahuje do formulare, kde pocita cenu, to ale neni zas tak moc dulezity; jde mi o ty spodni radky
var w = sMinus + f.slice( 0, f.length-2 ) + "." + f.slice( f.length-2, f.length );


var poprawnyFloat = /^-?[0-9]{1,}[.]{1}[0-9]{1,}$/i;
, generujou totiz cenu ve formatu cislo.00 a ja bych chtel jenom cislo, mozna to je i trochu pres regulerni vyrazy, jak na to, prosim?

dekuji
vinnetou
Profil *
A neslo by to judelat takhle:
cena=parseInt(Number(cena))
larryonov
Profil *
uz jsem to vyresil (mazanim)

var w = sMinus + f.slice( 0, f.length-2 );
var poprawnyFloat = /^-?[0-9]{1,}$/i;
taurendilek
Profil
pouzij parseInt, je to lepsi
Toto téma je uzamčeno. Odpověď nelze zaslat.

0