yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Quintiq file version 2.0
#parent: #root
StaticMethod GetFormatNrDecimals (Real value1, Real value2) const declarative remote as Number
{
  Description: 'Get the amount of decimals needed to show a good comparison between the two values'
  TextBody:
  [*
    nr_decimals := 0;
    
    if( value1 = value2 )
    {
      value := value1;
      
      // Determine the amount of decimals the values have
      nr_decimals := maxvalue( 0, ([String] value ).Length() - value.Format( 'N(Dec(0))' ).Length() - 1 );
    }
    else
    {
      // Determine the smallest non-zero value.
      smallest := abs( value2 - value1 );
      if( value1 <> 0.0 and abs( value1 ) < smallest )
      {
        smallest := abs( value1 );
      }
      if( value2 <> 0.0 and abs( value2 ) < smallest )
      {
        smallest := abs( value2 );
      }
      
      while( smallest < 0.95 and smallest > 0.0 )
      {
        smallest := smallest * 10;
        nr_decimals++;
      }
    }
    
    return nr_decimals;
  *]
  InterfaceProperties { Accessibility: 'Protected' }
}