Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá, estou usando um sistema e gostaria de mudar a forma como o preço é exibido, o formato padrão é usar 'ponto' para separar a casa decimal, gostaria de alterar para vírgula. Já tentei algumas vezes algumas possibilidades, mas nada funcionou... Alguém saberia como fazer isto? Os códigos php e java são:
PHP
/**
* Return price format and display
* @return float
* @param float $fPrice
*/
function displayPrice( $fPrice ){
return $fPrice;/**
* Return price format to save in database
* @return float
* @param float $fPrice
*/
function normalizePrice( $fPrice ){
return sprintf( '%01.2f', ereg_replace( ',', '.', $fPrice ) );/**
* Create price using two variables
* @return float
* @param float $fPrice1
* @param float $fPrice2
*/
function generatePrice( $fPrice1, $fPrice2 ){
if( ereg( '%', $fPrice2 ) ){
$fPrice2 = ereg_replace( '%', '', $fPrice2 );
if( $fPrice2 < 0 ){
return normalizePrice( $fPrice1 - ( $fPrice1 * ( -$fPrice2 / 100 ) ) );
}
else
return normalizePrice( $fPrice1 + ( $fPrice1 * ( $fPrice2 / 100 ) ) );
}
else{
return normalizePrice( $fPrice1 + $fPrice2 );
}function changePriceFormat( fPrice ){
// config start
var sDecimalSeparator = '.';
var sThousandSeparator = '';
// config end
fPrice = fix( fPrice );
var aPrice = fPrice.split( '.' );
var iPriceFull = aPrice[0];
var aPriceFull = new Array( );
var j = 0;
for( var i = iPriceFull.length - 1; i >= 0; i-- ){
if( j > 0 && j%3 == 0 )
aPriceFull[j] = iPriceFull.substr( i, 1 )+''+sThousandSeparator;
else
aPriceFull[j] = iPriceFull.substr( i, 1 );
j++;
} // end for
aPriceFull.reverse( );
sPriceFull = aPriceFull.join( '' );
sPrice = sPriceFull+''+sDecimalSeparator+''+aPrice[1];
return sPrice;
} // end function changePriceFormat
Isto são os códigos relacionados ao formato do preço, tentei mudar onde é ponto por vírgula, mas não funcionou...
Obrigado desde já.
Continuei tentando e já consegui resolver tudo... Desculpe o incomodo!
Posta sua solução, se alguém precisar saberá como fazer..
abs
>
Continuei tentando e já consegui resolver tudo... Desculpe o incomodo!
Posta sua solução, se alguém precisar saberá como fazer..
Na função displayPrice( $fPrice ) do PHP:
mudei:
return $fPrice;
para:
return number_format( $fPrice, 2, ',', '' );
Na função changePriceFormat( ) do Java:
mudei:
var sDecimalSeparator = '.';
var sThousandSeparator = '';
para:
var sDecimalSeparator = ',';
var sThousandSeparator = '';
Continuei tentando e já consegui resolver tudo... Desculpe o incomodo!