1 #ifndef __FREQUENCY_FORMATTER_HXX
2 #define __FREQUENCY_FORMATTER_HXX
4 /* ------------- A NAV/COMM Frequency formatter ---------------------- */
6 class FrequencyFormatter : public SGPropertyChangeListener {
8 FrequencyFormatter( SGPropertyNode_ptr freqNode, SGPropertyNode_ptr fmtFreqNode, double channelSpacing ) :
10 _fmtFreqNode( fmtFreqNode ),
11 _channelSpacing(channelSpacing)
13 _freqNode->addChangeListener( this );
14 valueChanged(_freqNode);
18 _freqNode->removeChangeListener( this );
21 void valueChanged (SGPropertyNode * prop)
23 // format as fixed decimal "nnn.nn"
24 std::ostringstream buf;
28 << std::setprecision(2)
30 _fmtFreqNode->setStringValue( buf.str() );
33 double getFrequency() const
35 double d = SGMiscd::roundToInt(_freqNode->getDoubleValue() / _channelSpacing) * _channelSpacing;
36 // strip last digit, do not round
37 return ((int)(d*100))/100.0;
41 SGPropertyNode_ptr _freqNode;
42 SGPropertyNode_ptr _fmtFreqNode;
43 double _channelSpacing;
47 #endif //__FREQUENCY_FORMATTER_HXX