ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/freemol/trunk/src/mengine/src/numeral.c
Revision: 110
Committed: Thu Mar 12 01:43:50 2009 UTC (12 years, 6 months ago) by gilbertke
File size: 1828 byte(s)
Log Message:
further cleanup and localization of atom data
Line User Rev File contents
1 tjod 3 #define EXTERN extern
2    
3     #include "pcwin.h"
4    
5     void numeral(int number, char *astring, int size)
6     {
7     int multi,length,minsize,million,hthou,tthou;
8     int thou, hun,tens,ones;
9     int right, negative;
10     char bstring[4];
11    
12     if (size == 0)
13     {
14     right = FALSE;
15     size = 1;
16     } else
17     right = TRUE;
18    
19     minsize = size;
20     length = size;
21    
22     if (number > 0)
23     negative = FALSE;
24     else
25     {
26     negative = TRUE;
27     number = -number;
28     }
29     million = number/1000000;
30     multi = 1000000*million;
31     hthou = (number-multi)/100000;
32     multi = multi + 100000*hthou;
33     tthou = (number-multi)/10000;
34     multi = multi + 10000*tthou;
35     thou = (number-multi)/1000;
36     multi = multi + 1000*thou;
37     hun = (number-multi)/100;
38     multi = multi + 100*hun;
39     tens = (number-multi)/10;
40     multi = multi + 10*tens;
41     ones = number - multi;
42    
43     if (million != 0)
44     size = 7;
45     else if (hthou != 0)
46     size = 6;
47     else if (tthou != 0)
48     size = 5;
49     else if (thou != 0)
50     size = 4;
51     else if (hun != 0)
52     size = 3;
53     else if (tens != 0)
54     size = 2;
55     else
56     size = 1;
57    
58     if ( length < size)
59     size = length;
60     if ( minsize > size)
61     size = minsize;
62    
63     sprintf(bstring,"%d",number);
64     size = strlen(bstring);
65    
66     if (size == 3)
67     {
68     astring[0] = bstring[0];
69     astring[1] = bstring[1];
70     astring[2] = bstring[2];
71     astring[3] = '\0';
72     } else if (size == 2)
73     {
74     bstring[2] = ' ';
75     astring[0] = bstring[2];
76     astring[1] = bstring[0];
77     astring[2] = bstring[1];
78     astring[3] = '\0';
79     } else if (size == 1)
80     {
81     bstring[2] = ' ';
82     astring[0] = bstring[2];
83     astring[1] = bstring[2];
84     astring[2] = bstring[0];
85     astring[3] = '\0';
86     }
87    
88     }