Commit 8537b493 authored by Dmitry.Shahtanov's avatar Dmitry.Shahtanov Committed by Alexander.Trofimov

fix: Bug 21009 - Некорректный формат отображения в ячейке для функции DOLLAR

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@50452 954022d7-b5bf-4e40-9824-e11837661b57
parent 4e332596
......@@ -177,11 +177,174 @@ cFormulaFunction.TextAndData = {
r.setArgumentsMin( 1 );
r.setArgumentsMax( 2 );
r.Calculate = function ( arg ) {
var res = cFormulaFunction.TextAndData["FIXED"]().Calculate( arg );
if ( res instanceof cError )
return this.value = res;
return this.value = new cString( "$" + res.getValue() );
function SignZeroPositive( number ) {
return number < 0 ? -1 : 1;
}
function truncate( n ) {
return Math[n > 0 ? "floor" : "ceil"]( n );
}
function sign( n ) {
return n == 0 ? 0 : n < 0 ? -1 : 1
}
function Floor( number, significance ) {
var quotient = number / significance;
if ( quotient == 0 ) {
return 0;
}
var nolpiat = 5 * sign( quotient ) * Math.pow( 10, Math.floor( Math.log( Math.abs( quotient ) ) / Math.log( 10 ) ) - cExcelSignificantDigits );
return truncate( quotient + nolpiat ) * significance;
}
function roundHelper( number, num_digits ) {
if ( num_digits > cExcelMaxExponent ) {
if ( Math.abs( number ) < 1 || num_digits < 1e10 ) // The values are obtained experimentally
{
return new cNumber( number );
}
return new cNumber( 0 );
}
else if ( num_digits < cExcelMinExponent ) {
if ( Math.abs( number ) < 0.01 ) // The values are obtained experimentally
{
return new cNumber( number );
}
return new cNumber( 0 );
}
var significance = SignZeroPositive( number ) * Math.pow( 10, -truncate( num_digits ) );
number += significance / 2;
if ( number / significance == Infinity ) {
return new cNumber( number );
}
return new cNumber( Floor( number, significance ) );
}
function toFix( str, skip ) {
var res, _int, _dec, _tmp = ""
if ( skip )
return str;
res = str.split( "." );
_int = res[0];
if ( res.length == 2 )
_dec = res[1];
_int = _int.split( "" ).reverse().join( "" ).match( /([^]{1,3})/ig )
for ( var i = _int.length - 1; i >= 0; i-- ) {
_tmp += _int[i].split( "" ).reverse().join( "" );
if ( i != 0 )
_tmp += ",";
}
if ( undefined != _dec )
while ( _dec.length < arg1.getValue() ) _dec += "0";
return "" + _tmp + ( res.length == 2 ? "." + _dec + "" : "");
}
var arg0 = arg[0],
arg1 = arg[1] ? arg[1] : new cNumber( 2 ),
arg2 = arg[2] ? arg[2] : new cBool( false );
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ) {
arg0 = arg0.cross( arguments[1].first );
}
if ( arg1 instanceof cArea || arg1 instanceof cArea3D ) {
arg1 = arg1.cross( arguments[1].first );
}
if ( arg2 instanceof cArea || arg2 instanceof cArea3D ) {
arg2 = arg2.cross( arguments[1].first );
}
if ( arg0 instanceof cError ) return this.value = arg0;
if ( arg1 instanceof cError ) return this.value = arg1;
if ( arg2 instanceof cError ) return this.value = arg2;
if ( arg0 instanceof cRef || arg0 instanceof cRef3D ) {
arg0 = arg0.getValue();
if ( arg0 instanceof cError ) return this.value = arg0;
else if ( arg0 instanceof cString ) return this.value = new cError( cErrorType.wrong_value_type );
else arg0 = arg0.tocNumber();
}
else arg0 = arg0.tocNumber();
if ( arg1 instanceof cRef || arg1 instanceof cRef3D ) {
arg1 = arg1.getValue();
if ( arg1 instanceof cError ) return this.value = arg1;
else if ( arg1 instanceof cString ) return this.value = new cError( cErrorType.wrong_value_type );
else arg1 = arg1.tocNumber();
}
else arg1 = arg1.tocNumber();
if ( arg0 instanceof cArray && arg1 instanceof cArray ) {
if ( arg0.getCountElement() != arg1.getCountElement() || arg0.getRowCount() != arg1.getRowCount() ) {
return this.value = new cError( cErrorType.not_available );
}
else {
arg0.foreach( function ( elem, r, c ) {
var a = elem;
b = arg1.getElementRowCol( r, c );
if ( a instanceof cNumber && b instanceof cNumber ) {
var res = roundHelper( a.getValue(), b.getValue() );
this.array[r][c] = toFix( res.toString(), arg2.toBool() );
}
else
this.array[r][c] = new cError( cErrorType.wrong_value_type );
} )
return this.value = arg0;
}
}
else if ( arg0 instanceof cArray ) {
arg0.foreach( function ( elem, r, c ) {
var a = elem;
b = arg1;
if ( a instanceof cNumber && b instanceof cNumber ) {
var res = roundHelper( a.getValue(), b.getValue() );
this.array[r][c] = toFix( res.toString(), arg2.toBool() );
}
else
this.array[r][c] = new cError( cErrorType.wrong_value_type );
} )
return this.value = arg0;
}
else if ( arg1 instanceof cArray ) {
arg1.foreach( function ( elem, r, c ) {
var a = arg0;
b = elem;
if ( a instanceof cNumber && b instanceof cNumber ) {
var res = roundHelper( a.getValue(), b.getValue() );
this.array[r][c] = toFix( res.toString(), arg2.toBool() );
}
else
this.array[r][c] = new cError( cErrorType.wrong_value_type );
} )
return this.value = arg1;
}
var number = arg0.getValue(), num_digits = arg1.getValue();
this.value = roundHelper( number, num_digits ).getValue();
var cNull = ""
if( num_digits > 0 ){
cNull=".";
for ( var i = 0; i < num_digits; i++, cNull += "0" ) {
}
}
this.value = new cString(oNumFormatCache.get("$#,##0"+cNull+";($#,##0"+cNull+")").format(roundHelper( number, num_digits ).getValue(), CellValueType.Number, gc_nMaxDigCount)[0].text)
return this.value;
}
r.getInfo = function () {
return {
......@@ -189,6 +352,7 @@ cFormulaFunction.TextAndData = {
args:"( number [ , num-decimal ] )"
};
}
r.setFormat(r.formatType.noneFormat);
return r;
},
'EXACT':function () {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment