1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_scui.hxx" 26 27 #ifdef SC_DLLIMPLEMENTATION 28 #undef SC_DLLIMPLEMENTATION 29 #endif 30 #include "editfield.hxx" 31 #include <rtl/math.hxx> 32 #include <unotools/localedatawrapper.hxx> 33 #include "global.hxx" 34 35 // ============================================================================ 36 37 namespace { 38 39 sal_Unicode lclGetDecSep() 40 { 41 return ScGlobal::GetpLocaleData()->getNumDecimalSep().GetChar( 0 ); 42 } 43 44 sal_Unicode lclGetGroupSep() 45 { 46 return ScGlobal::GetpLocaleData()->getNumThousandSep().GetChar( 0 ); 47 } 48 49 } // namespace 50 51 // ============================================================================ 52 53 ScDoubleField::ScDoubleField( Window* pParent, const ResId& rResId ) : 54 Edit( pParent, rResId ) 55 { 56 } 57 58 bool ScDoubleField::GetValue( double& rfValue ) const 59 { 60 String aStr( GetText() ); 61 aStr.EraseLeadingAndTrailingChars( ' ' ); 62 bool bOk = aStr.Len() > 0; 63 if( bOk ) 64 { 65 rtl_math_ConversionStatus eStatus; 66 sal_Int32 nEnd; 67 rfValue = rtl::math::stringToDouble( aStr, lclGetDecSep(), lclGetGroupSep(), &eStatus, &nEnd ); 68 bOk = (eStatus == rtl_math_ConversionStatus_Ok) && (nEnd == static_cast< sal_Int32 >( aStr.Len() )); 69 } 70 return bOk; 71 } 72 73 void ScDoubleField::SetValue( double fValue, sal_Int32 nDecPlaces, bool bEraseTrailingDecZeros ) 74 { 75 SetText( ::rtl::math::doubleToUString( fValue, rtl_math_StringFormat_G, 76 nDecPlaces, lclGetDecSep(), bEraseTrailingDecZeros ) ); 77 } 78 79 // ============================================================================ 80 81