32#include <tqdatetime.h>
36#include <kcalendarsystem.h>
39#include "kspread_util.h"
40#include "kspread_value.h"
42namespace NumFormat_Local
44 enum { Unknown, TimeDate, Number, Scientific, Fraction } Type;
129 class NumberFormat :
public BaseFormat
143 class FractionFormat :
public BaseFormat
157 class DateTimeFormat :
public BaseFormat
164 class ScientificFormat :
public BaseFormat
183 int getType( TQString
const & format, BaseFormat * f )
const
185 FormatMap::const_iterator iter = m_formats.find( format );
186 if ( iter == m_formats.end() )
196 void addFraction( TQString
const & format, FractionFormat * f )
198 m_formats.insert( format, f );
201 void addNumber( TQString
const & format, NumberFormat * n )
203 m_formats.insert( format, n );
206 void addDateTime( TQString
const & format, DateTimeFormat * d )
208 m_formats.insert( format, d );
211 void addScientific( TQString
const & format, ScientificFormat * d )
213 m_formats.insert( format, d );
217 class FormatMap :
public TQMap<TQString, BaseFormat *> {};
226 ConvertionInfo g_convertionInfo;
229 FormatStore g_formatStore;
232using namespace NumFormat_Local;
237 g_convertionInfo.dt = 0;
238 g_convertionInfo.thSet =
false;
239 g_convertionInfo.showMinus =
true;
240 g_convertionInfo.negRed =
false;
241 g_convertionInfo.negBr =
false;
242 g_convertionInfo.reqCounter = 0;
243 g_convertionInfo.reqFirst = 0;
244 g_convertionInfo.prefix =
"";
245 g_convertionInfo.postfix =
"";
246 g_convertionInfo.rightOpt = 0;
247 g_convertionInfo.rightReq = 0;
248 g_convertionInfo.leftReq = 0;
249 g_convertionInfo.rightSpace = 0;
250 g_convertionInfo.leftSpace = 0;
251 g_convertionInfo.optFirst = 0;
252 g_convertionInfo.upReq = 0;
253 g_convertionInfo.ampm =
false;
256void initGlobals( TDELocale
const *
const locale )
258 g_Monday = locale->calendar()->weekDayName( 1,
false );
259 g_Tuesday = locale->calendar()->weekDayName( 2,
false );
260 g_Wednesday = locale->calendar()->weekDayName( 3,
false );
261 g_Thursday = locale->calendar()->weekDayName( 4,
false );
262 g_Friday = locale->calendar()->weekDayName( 5,
false );
263 g_Saturday = locale->calendar()->weekDayName( 6,
false );
264 g_Sunday = locale->calendar()->weekDayName( 7,
false );
265 g_Mon = locale->calendar()->weekDayName( 1,
true );
266 g_Tue = locale->calendar()->weekDayName( 2,
true );
267 g_Wed = locale->calendar()->weekDayName( 3,
true );
268 g_Thu = locale->calendar()->weekDayName( 4,
true );
269 g_Fri = locale->calendar()->weekDayName( 5,
true );
270 g_Sat = locale->calendar()->weekDayName( 6,
true );
271 g_Sun = locale->calendar()->weekDayName( 7,
true );
272 g_January = locale->calendar()->monthName( 1, 2005,
false );
273 g_February = locale->calendar()->monthName( 2, 2005,
false );
274 g_March = locale->calendar()->monthName( 3, 2005,
false );
275 g_April = locale->calendar()->monthName( 4, 2005,
false );
276 g_MayL = locale->calendar()->monthName( 5, 2005,
false );
277 g_June = locale->calendar()->monthName( 6, 2005,
false );
278 g_July = locale->calendar()->monthName( 7, 2005,
false );
279 g_August = locale->calendar()->monthName( 8, 2005,
false );
280 g_September = locale->calendar()->monthName( 9, 2005,
false );
281 g_October = locale->calendar()->monthName( 10, 2005,
false );
282 g_November = locale->calendar()->monthName( 11, 2005,
false );
283 g_December = locale->calendar()->monthName( 12, 2005,
false );
284 g_Jan = locale->calendar()->monthName( 1, 2005,
true );
285 g_Feb = locale->calendar()->monthName( 2, 2005,
true );
286 g_Mar = locale->calendar()->monthName( 3, 2005,
true );
287 g_Apr = locale->calendar()->monthName( 4, 2005,
true );
288 g_May = locale->calendar()->monthName( 5, 2005,
true );
289 g_Jun = locale->calendar()->monthName( 6, 2005,
true );
290 g_Jul = locale->calendar()->monthName( 7, 2005,
true );
291 g_Aug = locale->calendar()->monthName( 8, 2005,
true );
292 g_Sep = locale->calendar()->monthName( 9, 2005,
true );
293 g_Oct = locale->calendar()->monthName( 10, 2005,
true );
294 g_Nov = locale->calendar()->monthName( 11, 2005,
true );
295 g_Dec = locale->calendar()->monthName( 12, 2005,
true );
297 g_dcSymbol = locale->decimalSymbol()[0];
298 g_thSymbol = locale->thousandsSeparator()[0];
299 g_posSymbol = locale->positiveSign()[0];
300 g_negSymbol = locale->negativeSign()[0];
305void convertDateTime(
Value const & value )
308 TQDate d( dt.date() );
309 TQTime t( dt.time() );
311 g_dateTime.year = d.year();
312 g_dateTime.month = d.month();
313 g_dateTime.day = d.day();
314 g_dateTime.hour = t.hour();
315 g_dateTime.minute = t.minute();
316 g_dateTime.second = t.second();
318 g_convertionInfo.dt = &g_dateTime;
321void parseNegativePart( TQString & format,
int i,
322 int l,
bool acceptDigits )
324 g_convertionInfo.showMinus =
false;
325 g_convertionInfo.negRed =
false;
326 g_convertionInfo.negRed =
false;
329 while ( i < l && !end)
331 TQChar c( format[i] );
335 g_convertionInfo.showMinus =
true;
338 g_convertionInfo.negBr =
true;
341 if ( format.find(
"[red]", i,
false ) == i )
343 g_convertionInfo.negRed =
true;
355 for (
int j = l - 1; j > i; --j )
357 if ( format[j] ==
'"' )
363 if ( !quote && ( format[j] ==
'0' || format[j] !=
'?'
365 || ( format[j].isDigit() && acceptDigits ) ) )
367 g_convertionInfo.postfix = format.mid( j + 1 );
368 format.remove( (
unsigned int) (j + 1), (
unsigned int) (l - j) );
373 int p = g_convertionInfo.postfix.find(
'"' );
376 g_convertionInfo.postfix.remove( p, 1 );
378 p = g_convertionInfo.postfix.find(
'"', p );
382void createNumberStruct( BaseFormat * data, TQString
const & format,
bool insert )
384 NumberFormat * d =
new NumberFormat();
386 d->prefix = g_convertionInfo.prefix;
387 d->postfix = g_convertionInfo.postfix;
388 d->thSet = g_convertionInfo.thSet;
389 d->showMinus = g_convertionInfo.showMinus;
390 d->negRed = g_convertionInfo.negRed;
391 d->negBr = g_convertionInfo.negBr;
392 d->rightOpt = g_convertionInfo.rightOpt;
393 d->rightReq = g_convertionInfo.rightReq;
394 d->leftReq = g_convertionInfo.leftReq;
395 d->rightSpace = g_convertionInfo.rightSpace;
396 d->leftSpace = g_convertionInfo.leftSpace;
399 g_formatStore.addNumber( format, d );
403void createDateTimeStruct( BaseFormat * data, TQString
const & format,
404 TQString
const & optFormat,
bool insert )
406 DateTimeFormat * d =
new DateTimeFormat();
408 d->prefix = g_convertionInfo.prefix;
409 d->postfix = g_convertionInfo.postfix;
410 d->ampm = g_convertionInfo.ampm;
411 d->format = optFormat;
414 g_formatStore.addDateTime( format, d );
418void createScientificStruct( BaseFormat * data, TQString
const & format,
bool insert )
420 ScientificFormat * d =
new ScientificFormat();
421 d->type = Scientific;
422 d->prefix = g_convertionInfo.prefix;
423 d->postfix = g_convertionInfo.postfix;
424 d->thSet = g_convertionInfo.thSet;
425 d->showMinus = g_convertionInfo.showMinus;
426 d->negRed = g_convertionInfo.negRed;
427 d->negBr = g_convertionInfo.negBr;
428 d->rightOpt = g_convertionInfo.rightOpt;
429 d->rightReq = g_convertionInfo.rightReq;
430 d->leftReq = g_convertionInfo.leftReq;
431 d->rightSpace = g_convertionInfo.rightSpace;
432 d->leftSpace = g_convertionInfo.leftSpace;
433 d->upReq = g_convertionInfo.upReq;
436 g_formatStore.addScientific( format, d );
441int doPreScan( TQString & format, TQString
const & formatBack, TDELocale
const *
const ,
442 bool insert, BaseFormat * data )
444 int type = g_formatStore.getType( format, data );
450 int l = format.length();
458 bool endFixed =
false;
460 FractionFormat * df = 0;
473 g_convertionInfo.postfix += format.mid( i );
474 format.remove( i, l - i );
477 TQChar ch( format[i] );
481 if ( type == Number )
484 if ( format[ i + 1] ==
'$' )
488 while ( i < l && format[i] !=
']' )
490 if ( format[i] ==
'-' )
495 g_convertionInfo.prefix += format[i];
497 g_convertionInfo.postfix += format[i];
498 format.remove( i, 1 );
508 g_convertionInfo.postfix +=
'[';
509 format.remove( i, 1 );
513 if ( ( format[ i + 1].lower() !=
's' )
514 && ( format[ i + 1].lower() !=
'm' )
515 && ( format[ i + 1].lower() !=
'h' ) )
520 g_convertionInfo.postfix += format[i];
522 g_convertionInfo.prefix += format[i];
523 format.remove( i, 1 );
530 TQChar c( format[i] );
532 while ( i < l && format[i] !=
']' )
534 if ( format[i] != c )
536 format.remove( i, 1 );
551 if ( type == Number )
555 g_convertionInfo.postfix += format[i];
557 g_convertionInfo.prefix += format[i];
558 format.remove( i, 1 );
564 if ( !dcSeen && leftReq > 0 )
566 format.remove( i, 1 );
572 ++g_convertionInfo.rightOpt;
576 if ( spaceInNum > 0 )
578 ++g_convertionInfo.reqCounter;
582 if ( !dcSeen && rightOpt > 0 )
584 format.remove( i, 1 );
588 ++g_convertionInfo.leftReq;
590 ++g_convertionInfo.rightReq;
594 if ( ( i + 1 < l ) && ( format[i + 1] ==
' ' ) )
598 if ( format[i] !=
'?' && !format[i].isDigit() && format[i] !=
'#' )
600 g_convertionInfo.postfix = format.mid(i);
601 format.remove( i, l - i );
613 if ( format[i] ==
';' )
616 parseNegativePart( format, i, l,
true );
621 if ( ( format[i + 1] ==
')' ) && ( format[i + 2] ==
';' ) )
624 parseNegativePart( format, i, l,
true );
630 f = frac.toInt( &ok );
632 df =
new FractionFormat();
638 df->thSet = g_convertionInfo.thSet;
639 df->showMinus = g_convertionInfo.showMinus;
640 df->negRed = g_convertionInfo.negRed;
641 df->negBr = g_convertionInfo.negBr;
642 df->fractionDigists = d;
643 df->reqCounter = g_convertionInfo.reqCounter;
644 df->reqFirst = g_convertionInfo.reqFirst;
645 df->prefix = g_convertionInfo.prefix;
646 df->postfix = g_convertionInfo.postfix;
649 g_formatStore.addFraction( formatBack, df );
656 if ( type == Unknown )
658 g_convertionInfo.prefix +=
',';
660 else if ( type == Number )
664 g_convertionInfo.postfix +=
',';
665 format.remove( i, 1 );
672 format.remove( i, 1 );
681 if ( type == Unknown )
685 && ( format[j] ==
'0' || format[j] ==
'#' ) )
693 g_convertionInfo.postfix +=
'.';
695 g_convertionInfo.prefix +=
'.';
696 format.remove( i, 1 );
700 else if ( type == Number )
712 while ( i < l && format[i] !=
'"' )
717 if ( type == Unknown )
718 g_convertionInfo.prefix += s;
721 g_convertionInfo.postfix += s;
724 format.remove( i, len );
729 if ( type == Number )
734 if ( ( format[i + 1] !=
')' ) || ( format[i + 2] !=
';' ) )
739 parseNegativePart( format, i, l,
false );
741 createNumberStruct( data, formatBack, insert );
749 g_convertionInfo.postfix += format.mid( i );
750 format.remove( i, l - i );
752 createNumberStruct( data, formatBack, insert );
760 if ( type == Unknown )
762 g_convertionInfo.postfix +=
';';
763 format.remove( i, 1 );
768 if ( type == Number )
771 parseNegativePart( format, i, l,
false );
773 createNumberStruct( data, formatBack, insert );
778 if ( type == Scientific )
781 parseNegativePart( format, i, l,
false );
783 createScientificStruct( data, formatBack, insert );
790 if ( type == Number )
792 g_convertionInfo.optFirst = (leftOpt > 0 ? leftOpt : 0);
793 g_convertionInfo.reqFirst = (leftReq > 0 ? leftReq : 0);
796 g_convertionInfo.postfix +=
' ';
798 else if ( type == Unknown )
800 g_convertionInfo.prefix +=
' ';
801 format.remove( i, 1 );
808 if ( type == TimeDate || type == Unknown )
810 if ( ( i + 1 < l ) && ( format[i + 1].lower() ==
'm' ) )
812 g_convertionInfo.ampm =
true;
814 if ( ( i + 3 < l ) && ( format[i + 1] ==
'/' )
815 && ( format[i + 2].lower() ==
'p' )
816 && ( format[i + 3].lower() ==
'm' ) )
821 else if ( type == Unknown )
823 g_convertionInfo.prefix += format[i];
824 format.remove( i, 1 );
832 g_convertionInfo.postfix += format[i];
833 format.remove( i, 1 );
840 if ( type == TimeDate || type == Unknown )
842 if ( ( i + 1 < l ) && ( format[i + 1].lower() ==
'm' ) )
844 g_convertionInfo.ampm =
true;
847 else if ( type == Unknown )
849 g_convertionInfo.prefix += format[i];
850 format.remove( i, 1 );
858 g_convertionInfo.postfix += format[i];
859 format.remove( i, 1 );
866 if ( type == Unknown )
868 else if ( type != TimeDate )
876 if ( type != Unknown && type != TimeDate )
886 if ( type != Unknown && type != TimeDate )
893 if ( type == Unknown )
895 g_convertionInfo.prefix += format[i];
896 format.remove( i, 1 );
899 else if ( type == Number || type == Scientific
900 || type == Fraction )
903 g_convertionInfo.postfix += format[i];
904 format.remove( i, 1 );
912 if ( type == Number )
913 createNumberStruct( data, formatBack, insert );
914 else if ( type == TimeDate )
915 createDateTimeStruct( data, formatBack, format, insert );
916 else if ( type == Scientific )
917 createScientificStruct( data, formatBack, insert );
922void createNumber( TQString & result,
Value const & value,
923 TQString
const & ,
bool & setRed,
924 NumberFormat
const *
const data )
926 int prec = data->rightReq + data->rightOpt;
928 double m[] = { 1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10 };
929 double mm = ( prec > 10 ) ? pow( 10.0, prec ) : m[prec];
931 num = floor( fabs( num ) * mm + 0.5 ) / mm;
933 bool negative = ( num < 0 ? true : false );
934 double nnum = ( negative ? -num : num );
936 result = TQString::number( nnum,
'f', prec );
938 int pos = result.find(
'.' );
941 result = result.replace( pos, 1, g_dcSymbol );
944 if ( data->rightOpt > 0 )
946 int i = result.length() - 1;
947 int n = result.length() - data->rightOpt;
951 if ( result[i] !=
'0' )
954 result = result.left( i + 1 );
957 result = result.remove( i, 1 );
961 while ( data->leftReq > pos )
963 result.prepend(
'0' );
968 if ( data->thSet && pos > 3 )
973 result.insert( l, g_thSymbol );
979 if ( data->leftSpace > 0 )
981 for (
int i = 0; i < data->leftSpace; ++i )
982 result.prepend(
' ' );
984 if ( data->rightSpace > 0 )
986 for (
int i = 0; i < data->rightSpace; ++i )
987 result.append(
' ' );
992 if ( data->showMinus )
993 result.prepend( g_negSymbol );
997 result.prepend(
'(' );
998 result.append(
')' );
1005 result.prepend( data->prefix );
1006 result.append( data->postfix );
1009void createFraction( TQString & result,
Value const & value,
1010 TQString
const & ,
bool & setRed,
1011 FractionFormat
const *
const data )
1015 bool negative = ( num < 0 ? true : false );
1017 double fnum = floor( negative ? -num : num );
1019 double dec = num - fnum;
1023 if ( data->fraction <= 0 )
1026 double nnum = ( negative ? -num : num );
1027 double precision, denominator, numerator;
1028 int index = 2 + data->fractionDigists;
1030 if ( data->fractionDigists == 2 )
1032 if ( data->fractionDigists >= 3 )
1038 double val2 = rint( nnum );
1040 double inter4, p, q;
1041 inter4 = p = q = 0.0;
1043 precision = pow( 10.0, - index );
1047 while ( fabs( numerator / denominator - nnum ) > precision )
1049 val1 = (1 / ( val1 - val2 ) );
1050 val2 = rint( val1 );
1051 p = val2 * numerator + inter2;
1052 q = val2 * denominator + inter4;
1054 inter4 = denominator;
1060 }
while ( fabs( denominator ) > limit );
1062 index = (int) fabs( numerator );
1063 fraction = (int) fabs( denominator );
1068 fraction = data->fraction;
1073 for (
int i = 1; i <= fraction; ++i )
1075 calc = i * 1.0 / index;
1076 d = fabs( dec - calc );
1088 if ( data->optFirst == 0 && data->reqFirst == 0 && fnum > 0 )
1089 index += (int) (fnum * fraction);
1096 TQString denominator;
1098 numerator = TQString::number( index );
1099 int n = numerator.length() - data->reqCounter;
1100 for (
int i = 0; i < n; ++i )
1102 numerator.prepend(
'0' );
1105 denominator = TQString::number( fraction );
1106 frac = numerator +
'/' + denominator;
1109 if ( data->optFirst > 0 || data->reqFirst > 0 )
1111 if ( fnum == 0 && data->reqFirst > 0 )
1113 for (
int i = 0; i < data->reqFirst; ++i )
1116 else if ( fnum > 0 )
1118 left = TQString::number( fnum );
1119 int n = data->reqFirst - left.length();
1122 for (
int i = 0; i < n; ++i )
1124 left.prepend(
'0' );
1132 int l = left.length() - 3;
1135 left.insert( l, g_thSymbol );
1140 left = left +
' ' + frac;
1144 if ( data->showMinus )
1145 left.prepend( g_negSymbol );
1149 left.prepend(
'(' );
1160void createScientific( TQString & result,
Value const & value,
1161 TQString
const & ,
bool & setRed,
1162 ScientificFormat
const *
const data )
1166 bool negative = ( num < 0 ? true : false );
1167 double nnum = ( negative ? -num : num );
1169 result = TQString::number( nnum,
'E', data->rightReq + data->rightOpt );
1171 int pos = result.find(
'.' );
1174 result = result.replace( pos, 1, g_dcSymbol );
1175 if ( data->rightOpt > 0 )
1177 int i = result.find(
'E', pos,
false ) - 1;
1178 int n = result.length() - data->rightOpt;
1183 for ( ; i > n; --i )
1185 if ( result[i] !=
'0' )
1190 result = result.remove( i + 1, rem );
1194 while ( data->leftReq > pos )
1196 result.prepend(
'0' );
1200 if ( data->thSet && pos > 3 )
1205 result.insert( l, g_thSymbol );
1213 if ( data->showMinus )
1214 result.prepend( g_negSymbol );
1218 result.prepend(
'(' );
1219 result.append(
')' );
1226 result.prepend( data->prefix );
1227 result.append( data->postfix );
1230void appendAMPM( TQString & result,
Value const & value )
1232 if ( !g_convertionInfo.dt )
1233 convertDateTime( value );
1235 int hour = g_convertionInfo.dt->hour;
1237 result.append( i18n(
"PM") );
1239 result.append( i18n(
"AM") );
1242void appendHour( TQString & result,
Value const & value,
1243 int digits,
bool elapsed,
bool ampm )
1245 if ( !g_convertionInfo.dt )
1246 convertDateTime( value );
1248 int hour = g_convertionInfo.dt->hour;
1251 TQDate d1( g_convertionInfo.dt->year, g_convertionInfo.dt->month, g_convertionInfo.dt->day );
1252 TQDate d2( 1900, 1, 1 );
1253 hour += ( d2.daysTo( d1 ) * 24 );
1255 if ( hour < 10 && digits == 2 )
1258 if ( hour > 12 && ampm )
1261 if ( digits == 2 && hour < 10 )
1265 result += TQString::number( hour );
1268void appendMinutes( TQString & result,
Value const & value,
1269 int digits,
bool elapsed )
1271 if ( !g_convertionInfo.dt )
1272 convertDateTime( value );
1274 int minute = g_convertionInfo.dt->minute;
1277 TQDate d1( g_convertionInfo.dt->year, g_convertionInfo.dt->month, g_convertionInfo.dt->day );
1278 TQDate d2( 1900, 1, 1 );
1279 minute += ( d2.daysTo( d1 ) * 24 * 60 );
1281 if ( minute < 10 && digits == 2 )
1284 result += TQString::number( minute );
1287void appendSecond( TQString & result,
Value const & value,
1288 int digits,
bool elapsed )
1290 if ( !g_convertionInfo.dt )
1291 convertDateTime( value );
1293 int second = g_convertionInfo.dt->second;
1296 TQDate d1( g_convertionInfo.dt->year, g_convertionInfo.dt->month, g_convertionInfo.dt->day );
1297 TQDate d2( 1900, 1, 1 );
1298 second += ( d2.daysTo( d1 ) * 24 * 60 * 60 );
1300 if ( second < 10 && digits == 2 )
1303 result += TQString::number( second );
1306void appendYear( TQString & result,
Value const & value,
1309 if ( !g_convertionInfo.dt )
1310 convertDateTime( value );
1312 int year = g_convertionInfo.dt->year;
1314 result += TQString::number( year ).right( 2 );
1316 result += TQString::number( year );
1319void appendMonth( TQString & result,
Value const & value,
1322 if ( !g_convertionInfo.dt )
1323 convertDateTime( value );
1325 int month = g_convertionInfo.dt->month;
1327 result += TQString::number( month );
1334 result += TQString::number( month );
1341 result += ( digits != 3 ? g_January : g_Jan );
1345 result += ( digits != 3 ? g_February : g_Feb );
1349 result += ( digits != 3 ? g_March : g_Mar );
1353 result += ( digits != 3 ? g_April : g_Apr );
1357 result += ( digits != 3 ? g_MayL : g_May );
1361 result += ( digits != 3 ? g_June : g_Jun );
1365 result += ( digits != 3 ? g_July : g_Jul );
1369 result += ( digits != 3 ? g_August : g_Aug );
1373 result += ( digits != 3 ? g_September : g_Sep );
1377 result += ( digits != 3 ? g_October : g_Oct );
1381 result += ( digits != 3 ? g_November : g_Nov );
1385 result += ( digits != 3 ? g_December : g_Dec );
1391void appendDays( TQString & result,
Value const & value,
1394 if ( !g_convertionInfo.dt )
1395 convertDateTime( value );
1397 int day = g_convertionInfo.dt->day;
1399 result += TQString::number( day );
1406 result += TQString::number( day );
1410 TQDate date( g_convertionInfo.dt->year, g_convertionInfo.dt->month, g_convertionInfo.dt->day );
1411 int weekDay = date.dayOfWeek();
1415 result += ( digits != 3 ? g_Monday : g_Mon );
1419 result += ( digits != 3 ? g_Tuesday : g_Tue );
1423 result += ( digits != 3 ? g_Wednesday : g_Wed );
1427 result += ( digits != 3 ? g_Thursday : g_Thu );
1431 result += ( digits != 3 ? g_Friday : g_Fri );
1435 result += ( digits != 3 ? g_Saturday : g_Sat );
1439 result += ( digits != 3 ? g_Sunday : g_Sun );
1445void createDateTime( TQString & result,
Value const & value,
1447 DateTimeFormat
const *
const data )
1449 result = data->prefix;
1450 bool elapsed =
false;
1451 bool elapsedFound =
false;
1452 bool minute =
false;
1455 int l = (int) data->format.length();
1458 switch( data->format[i].lower() )
1464 if ( data->format[i] ==
'"' )
1467 result += data->format[i];
1477 elapsedFound =
true;
1490 if ( data->format[i + 1] ==
'h' )
1492 appendHour( result, value, 2, elapsed, data->ampm );
1496 appendHour( result, value, 1, elapsed, data->ampm );
1502 while ( data->format[i + 1] ==
'm' )
1509 appendMinutes( result, value, digits, elapsed );
1511 appendMonth( result, value, digits );
1517 if ( data->format[i + 1] ==
's' )
1519 appendSecond( result, value, 2, elapsed );
1523 appendSecond( result, value, 1, elapsed );
1530 while ( data->format[i + 1] ==
'd' )
1535 appendDays( result, value, digits );
1542 while ( data->format[i + 1] ==
'y' )
1547 appendYear( result, value, digits );
1552 if ( data->format[i + 1] ==
'm' )
1555 if ( data->format[i + 1] ==
'/'
1556 && data->format[i + 2].lower() ==
'p'
1557 && data->format[i + 3].lower() ==
'm' )
1560 appendAMPM( result, value );
1564 result += data->format[i];
1570 result += data->postfix;
1573TQString formatNumber(
Value const & value, TQString format,
bool & setRed,
1574 TDELocale
const *
const locale,
bool insert )
1578 initGlobals( locale );
1580 TQString backup( format );
1582 BaseFormat * data = 0;
1585 int t = doPreScan( format, backup, locale, insert, data );
1589 createNumber( result, value, format, setRed, (NumberFormat *) data );
1592 delete (NumberFormat *) data;
1596 else if ( t == Fraction )
1598 createFraction( result, value, format, setRed, (FractionFormat *) data );
1601 delete (FractionFormat *) data;
1605 else if ( t == Scientific )
1607 createScientific( result, value, format, setRed, (ScientificFormat *) data );
1610 delete (ScientificFormat *) data;
1614 else if ( t == TimeDate )
1616 createDateTime( result, value, format, (DateTimeFormat *) data );
1619 delete (DateTimeFormat *) data;
1623 else if ( data != 0 )
1625 result = data->prefix + data->postfix;
Provides a wrapper for cell value.
double asFloat() const
Returns the floating-point value of this value.
TQDateTime asDateTime() const
Returns the date/time representation of this value.