• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DomCR / ACadSharp / 17737836230

15 Sep 2025 03:12PM UTC coverage: 2.092% (-76.2%) from 78.245%
17737836230

push

github

web-flow
Merge pull request #790 from DomCR/addflag-refactor

addflag refactor

141 of 9225 branches covered (1.53%)

Branch coverage included in aggregate %.

0 of 93 new or added lines in 10 files covered. (0.0%)

24910 existing lines in 372 files now uncovered.

724 of 32119 relevant lines covered (2.25%)

5.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/ACadSharp/Types/Units/UnitStyleFormat.cs
1
using ACadSharp.Tables;
2
using CSMath;
3
using System;
4
using System.Globalization;
5
using System.Text;
6

7
namespace ACadSharp.Types.Units
8
{
9
        /// <summary>
10
        /// Represents the parameters to convert linear and angular units to its string representation.
11
        /// </summary>
12
        public class UnitStyleFormat
13
        {
14
                /// <summary>
15
                /// Gets or sets the number of decimal places for angular units.
16
                /// </summary>
17
                public short AngularDecimalPlaces
18
                {
UNCOV
19
                        get { return this._angularDecimalPlaces; }
×
20
                        set
UNCOV
21
                        {
×
UNCOV
22
                                if (value < 0)
×
23
                                {
×
24
                                        throw new ArgumentOutOfRangeException(nameof(value), value, "The number of decimal places must be equals or greater than zero.");
×
25
                                }
UNCOV
26
                                this._angularDecimalPlaces = value;
×
UNCOV
27
                        }
×
28
                }
29

30
                /// <summary>
31
                /// Gets or sets the suppression of zeros in the angular values.
32
                /// </summary>
UNCOV
33
                public ZeroHandling AngularZeroHandling { get; set; } = ZeroHandling.SuppressDecimalTrailingZeroes;
×
34

35
                /// <summary>
36
                /// Gets or set the decimal separator.
37
                /// </summary>
UNCOV
38
                public string DecimalSeparator { get; set; }
×
39

40
                /// <summary>
41
                /// Gets or set the angle degrees symbol.
42
                /// </summary>
UNCOV
43
                public string DegreesSymbol { get; set; }
×
44

45
                /// <summary>
46
                /// Gets or sets the separator between feet and inches.
47
                /// </summary>
UNCOV
48
                public string FeetInchesSeparator { get; set; }
×
49

50
                /// <summary>
51
                /// Gets or set the feet symbol.
52
                /// </summary>
UNCOV
53
                public string FeetSymbol { get; set; }
×
54

55
                /// <summary>
56
                /// Gets or sets the scale of fractions relative to dimension text height.
57
                /// </summary>
58
                public double FractionHeightScale
59
                {
UNCOV
60
                        get { return this._fractionHeightScale; }
×
61
                        set
UNCOV
62
                        {
×
UNCOV
63
                                if (value <= 0)
×
64
                                {
×
65
                                        throw new ArgumentOutOfRangeException(nameof(value), value, "The fraction height scale must be greater than zero.");
×
66
                                }
UNCOV
67
                                this._fractionHeightScale = value;
×
UNCOV
68
                        }
×
69
                }
70

71
                /// <summary>
72
                /// Gets or sets the fraction format for architectural or fractional units.
73
                /// </summary>
74
                /// <remarks>
75
                /// Horizontal stacking<br/>
76
                /// Diagonal stacking<br/>
77
                /// Not stacked (for example, 1/2)
78
                /// </remarks>
UNCOV
79
                public FractionFormat FractionType { get; set; }
×
80

81
                /// <summary>
82
                /// Gets or set the angle gradians symbol.
83
                /// </summary>
UNCOV
84
                public string GradiansSymbol { get; set; }
×
85

86
                /// <summary>
87
                /// Gets or set the inches symbol.
88
                /// </summary>
UNCOV
89
                public string InchesSymbol { get; set; }
×
90

91
                /// <summary>
92
                /// Gets or sets the number of decimal places for linear units.
93
                /// </summary>
94
                /// <remarks>
95
                /// For architectural and fractional the precision used for the minimum fraction is 1/2^LinearDecimalPlaces.
96
                /// </remarks>
97
                public short LinearDecimalPlaces
98
                {
UNCOV
99
                        get { return this._linearDecimalPlaces; }
×
100
                        set
UNCOV
101
                        {
×
UNCOV
102
                                if (value < 0)
×
103
                                {
×
104
                                        throw new ArgumentOutOfRangeException(nameof(value), value, "The number of decimal places must be equals or greater than zero.");
×
105
                                }
UNCOV
106
                                this._linearDecimalPlaces = value;
×
UNCOV
107
                        }
×
108
                }
109

110
                /// <summary>
111
                /// Gets or sets the suppression of zeros in the linear values.
112
                /// </summary>
UNCOV
113
                public ZeroHandling LinearZeroHandling { get; set; } = ZeroHandling.SuppressDecimalTrailingZeroes;
×
114

115
                /// <summary>
116
                /// Gets or set the angle minutes symbol.
117
                /// </summary>
UNCOV
118
                public string MinutesSymbol { get; set; }
×
119

120
                /// <summary>
121
                /// Gets or set the angle radians symbol.
122
                /// </summary>
UNCOV
123
                public string RadiansSymbol { get; set; }
×
124

125
                /// <summary>
126
                /// Gets or set the angle seconds symbol.
127
                /// </summary>
UNCOV
128
                public string SecondsSymbol { get; set; }
×
129

130
                /// <summary>
131
                /// Suppresses leading zeros in angular decimal dimensions (for example, 0.5000 becomes .5000).
132
                /// </summary>
133
                public bool SuppressAngularLeadingZeros
134
                {
135
                        get
136
                        {
×
137
                                return this.LinearZeroHandling == ZeroHandling.SuppressDecimalLeadingZeroes
×
138
                                        || this.LinearZeroHandling == ZeroHandling.SuppressDecimalLeadingAndTrailingZeroes;
×
139
                        }
×
140
                }
141

142
                /// <summary>
143
                /// Suppresses trailing zeros in angular decimal dimensions (for example, 12.5000 becomes 12.5).
144
                /// </summary>
145
                public bool SuppressAngularTrailingZeros
146
                {
147
                        get
148
                        {
×
149
                                return this.LinearZeroHandling == ZeroHandling.SuppressDecimalTrailingZeroes
×
150
                                        || this.LinearZeroHandling == ZeroHandling.SuppressDecimalLeadingAndTrailingZeroes;
×
151
                        }
×
152
                }
153

154
                /// <summary>
155
                /// Suppresses leading zeros in linear decimal dimensions (for example, 0.5000 becomes .5000).
156
                /// </summary>
157
                public bool SuppressLinearLeadingZeros
158
                {
159
                        get
160
                        {
×
161
                                return this.LinearZeroHandling == ZeroHandling.SuppressDecimalLeadingZeroes
×
162
                                        || this.LinearZeroHandling == ZeroHandling.SuppressDecimalLeadingAndTrailingZeroes;
×
163
                        }
×
164
                }
165

166
                /// <summary>
167
                /// Suppresses trailing zeros in linear decimal dimensions (for example, 12.5000 becomes 12.5).
168
                /// </summary>
169
                public bool SuppressLinearTrailingZeros
170
                {
171
                        get
172
                        {
×
173
                                return this.LinearZeroHandling == ZeroHandling.SuppressDecimalTrailingZeroes
×
174
                                        || this.LinearZeroHandling == ZeroHandling.SuppressDecimalLeadingAndTrailingZeroes;
×
175
                        }
×
176
                }
177

178
                /// <summary>
179
                /// Suppresses zero feet in architectural dimensions.
180
                /// </summary>
181
                public bool SuppressZeroFeet
182
                {
183
                        get
UNCOV
184
                        {
×
UNCOV
185
                                return this.LinearZeroHandling == ZeroHandling.SuppressZeroFeetAndInches
×
UNCOV
186
                                        || this.LinearZeroHandling == ZeroHandling.SuppressZeroFeetShowZeroInches;
×
UNCOV
187
                        }
×
188
                }
189

190
                /// <summary>
191
                /// Suppresses zero inches in architectural dimensions.
192
                /// </summary>
193
                public bool SuppressZeroInches
194
                {
195
                        get
196
                        {
×
197
                                return this.LinearZeroHandling == ZeroHandling.SuppressZeroFeetAndInches
×
198
                                        || this.LinearZeroHandling == ZeroHandling.ShowZeroFeetSuppressZeroInches;
×
199
                        }
×
200
                }
201

202
                private short _angularDecimalPlaces;
203

204
                private double _fractionHeightScale;
205

206
                private short _linearDecimalPlaces;
207

208
                /// <summary>
209
                /// Initializes a new instance of the <c>UnitStyleFormat</c> class.
210
                /// </summary>
UNCOV
211
                public UnitStyleFormat()
×
UNCOV
212
                {
×
UNCOV
213
                        this._linearDecimalPlaces = 2;
×
UNCOV
214
                        this._angularDecimalPlaces = 0;
×
UNCOV
215
                        this.DecimalSeparator = ".";
×
UNCOV
216
                        this.FeetInchesSeparator = "-";
×
UNCOV
217
                        this.DegreesSymbol = "°";
×
UNCOV
218
                        this.MinutesSymbol = "\'";
×
UNCOV
219
                        this.SecondsSymbol = "\"";
×
UNCOV
220
                        this.RadiansSymbol = "r";
×
UNCOV
221
                        this.GradiansSymbol = "g";
×
UNCOV
222
                        this.FeetSymbol = "\'";
×
UNCOV
223
                        this.InchesSymbol = "\"";
×
UNCOV
224
                        this._fractionHeightScale = 1.0;
×
UNCOV
225
                        this.FractionType = FractionFormat.Horizontal;
×
UNCOV
226
                }
×
227

228
                /// <summary>
229
                /// Get the string format based on the zero handling of the style.
230
                /// </summary>
231
                /// <param name="isAngular"></param>
232
                /// <returns></returns>
233
                public string GetZeroHandlingFormat(bool isAngular = false)
UNCOV
234
                {
×
UNCOV
235
                        short decimalPlaces = this.LinearDecimalPlaces;
×
236
                        ZeroHandling handling;
237

UNCOV
238
                        if (isAngular)
×
UNCOV
239
                        {
×
UNCOV
240
                                handling = this.AngularZeroHandling;
×
UNCOV
241
                        }
×
242
                        else
UNCOV
243
                        {
×
UNCOV
244
                                handling = this.LinearZeroHandling;
×
UNCOV
245
                        }
×
246

UNCOV
247
                        char leading = handling == ZeroHandling.SuppressDecimalLeadingZeroes
×
UNCOV
248
                                   || handling == ZeroHandling.SuppressDecimalLeadingAndTrailingZeroes ?
×
UNCOV
249
                                   '#' : '0';
×
250

UNCOV
251
                        char trailing = handling == ZeroHandling.SuppressDecimalTrailingZeroes
×
UNCOV
252
                           || handling == ZeroHandling.SuppressDecimalLeadingAndTrailingZeroes ?
×
UNCOV
253
                           '#' : '0';
×
254

UNCOV
255
                        StringBuilder zeroes = new();
×
256

UNCOV
257
                        zeroes.Append(leading);
×
UNCOV
258
                        zeroes.Append(".");
×
259

UNCOV
260
                        for (int i = 0; i < decimalPlaces; i++)
×
UNCOV
261
                        {
×
UNCOV
262
                                zeroes.Append(trailing);
×
UNCOV
263
                        }
×
264

UNCOV
265
                        return zeroes.ToString();
×
UNCOV
266
                }
×
267

268
                /// <summary>
269
                /// Converts a value into its feet and fractional inches string representation.
270
                /// </summary>
271
                /// <param name="value"></param>
272
                /// <returns>A string that represents the value in feet and fractional inches.</returns>
273
                public string ToArchitectural(double value)
UNCOV
274
                {
×
UNCOV
275
                        int feet = (int)(value / 12);
×
UNCOV
276
                        double inchesDec = value - 12 * feet;
×
UNCOV
277
                        int inches = (int)inchesDec;
×
278

UNCOV
279
                        if (MathHelper.IsZero(inchesDec))
×
280
                        {
×
281
                                if (feet == 0)
×
282
                                {
×
283
                                        if (this.SuppressZeroFeet)
×
284
                                        {
×
285
                                                return string.Format("0{0}", this.InchesSymbol);
×
286
                                        }
287

288
                                        if (this.SuppressZeroInches)
×
289
                                        {
×
290
                                                return string.Format("0{0}", this.FeetSymbol);
×
291
                                        }
292

293
                                        return string.Format("0{0}{1}0{2}", this.FeetSymbol, this.FeetInchesSeparator, this.InchesSymbol);
×
294
                                }
295

296
                                if (this.SuppressZeroInches)
×
297
                                {
×
298
                                        return string.Format("{0}{1}", feet, this.FeetSymbol);
×
299
                                }
300

301
                                return string.Format("{0}{1}{2}0{3}", feet, this.FeetSymbol, this.FeetInchesSeparator, this.InchesSymbol);
×
302
                        }
303

UNCOV
304
                        getFraction(inchesDec, (short)Math.Pow(2, this.LinearDecimalPlaces), out int numerator, out int denominator);
×
305

UNCOV
306
                        if (numerator == 0)
×
307
                        {
×
308
                                if (inches == 0)
×
309
                                {
×
310
                                        if (feet == 0)
×
311
                                        {
×
312
                                                if (this.SuppressZeroFeet)
×
313
                                                {
×
314
                                                        return string.Format("0{0}", this.InchesSymbol);
×
315
                                                }
316

317
                                                if (this.SuppressZeroInches)
×
318
                                                {
×
319
                                                        return string.Format("0{0}", this.FeetSymbol);
×
320
                                                }
321

322
                                                return string.Format("0{0}{1}0{2}", this.FeetSymbol, this.FeetInchesSeparator, this.InchesSymbol);
×
323
                                        }
324

325
                                        if (this.SuppressZeroInches)
×
326
                                        {
×
327
                                                return string.Format("{0}{1}", feet, this.FeetSymbol);
×
328
                                        }
329

330
                                        return string.Format("{0}{1}{2}0{3}", feet, this.FeetSymbol, this.FeetInchesSeparator, this.InchesSymbol);
×
331
                                }
332
                                if (feet == 0)
×
333
                                {
×
334
                                        if (this.SuppressZeroFeet)
×
335
                                        {
×
336
                                                return string.Format("{0}{1}", inches, this.InchesSymbol);
×
337
                                        }
338

339
                                        return string.Format("0{0}{1}{2}{3}", this.FeetSymbol, this.FeetInchesSeparator, inches, this.InchesSymbol);
×
340
                                }
341

342
                                return string.Format("{0}{1}{2}{3}{4}", feet, this.FeetSymbol, this.FeetInchesSeparator, inches, this.InchesSymbol);
×
343
                        }
344

UNCOV
345
                        string text = string.Empty;
×
346
                        string feetStr;
UNCOV
347
                        if (this.SuppressZeroFeet && feet == 0)
×
348
                        {
×
349
                                feetStr = string.Empty;
×
350
                        }
×
351
                        else
UNCOV
352
                        {
×
UNCOV
353
                                feetStr = feet + this.FeetSymbol + this.FeetInchesSeparator;
×
UNCOV
354
                        }
×
355

UNCOV
356
                        switch (this.FractionType)
×
357
                        {
358
                                case FractionFormat.Diagonal:
359
                                        text = $"\\A1;{feetStr}{inches}{{\\H{this.FractionHeightScale}x;\\S{numerator}#{denominator};}}{this.InchesSymbol}";
×
360
                                        break;
×
361

362
                                case FractionFormat.Horizontal:
UNCOV
363
                                        text = $"\\A1;{feetStr}{inches}{{\\H{this.FractionHeightScale}x;\\S{numerator}/{denominator};}}{this.InchesSymbol}";
×
UNCOV
364
                                        break;
×
365

366
                                case FractionFormat.None:
367
                                        text = $"{feetStr}{inches} {numerator}/{denominator}{this.InchesSymbol}";
×
368
                                        break;
×
369
                        }
UNCOV
370
                        return text;
×
UNCOV
371
                }
×
372

373
                /// <summary>
374
                /// Converts a value into its decimal string representation.
375
                /// </summary>
376
                /// <param name="value"></param>
377
                /// <param name="isAngular"></param>
378
                /// <returns>A string that represents the value in decimal units.</returns>
379
                public string ToDecimal(double value, bool isAngular = false)
UNCOV
380
                {
×
UNCOV
381
                        NumberFormatInfo numberFormat = new NumberFormatInfo
×
UNCOV
382
                        {
×
UNCOV
383
                                NumberDecimalSeparator = this.DecimalSeparator
×
UNCOV
384
                        };
×
385

UNCOV
386
                        return value.ToString(this.GetZeroHandlingFormat(isAngular), numberFormat);
×
UNCOV
387
                }
×
388

389
                /// <summary>
390
                /// Converts an angle value in degrees into its degrees, minutes and seconds string representation.
391
                /// </summary>
392
                /// <param name="angle">Angle value in radians.</param>
393
                /// <returns></returns>
394
                /// <exception cref="ArgumentNullException"></exception>
395
                public string ToDegreesMinutesSeconds(double angle)
UNCOV
396
                {
×
UNCOV
397
                        double degrees = MathHelper.RadToDeg(angle);
×
UNCOV
398
                        double minutes = (degrees - (int)degrees) * 60;
×
UNCOV
399
                        double seconds = (minutes - (int)minutes) * 60;
×
400

UNCOV
401
                        NumberFormatInfo numberFormat = new NumberFormatInfo
×
UNCOV
402
                        {
×
UNCOV
403
                                NumberDecimalSeparator = this.DecimalSeparator
×
UNCOV
404
                        };
×
405

UNCOV
406
                        if (this.AngularDecimalPlaces == 0)
×
UNCOV
407
                        {
×
UNCOV
408
                                return string.Format(numberFormat, "{0}" + this.DegreesSymbol, (int)Math.Round(degrees, 0));
×
409
                        }
410

411
                        if (this.AngularDecimalPlaces == 1 || this.AngularDecimalPlaces == 2)
×
412
                        {
×
413
                                return string.Format(numberFormat, "{0}" + this.DegreesSymbol + "{1}" + this.MinutesSymbol, (int)degrees, (int)Math.Round(minutes, 0));
×
414
                        }
415

416
                        if (this.AngularDecimalPlaces == 3 || this.AngularDecimalPlaces == 4)
×
417
                        {
×
418
                                return string.Format(numberFormat, "{0}" + this.DegreesSymbol + "{1}" + this.MinutesSymbol + "{2}" + this.SecondsSymbol, (int)degrees, (int)minutes, (int)Math.Round(seconds, 0));
×
419
                        }
420

421
                        // the suppression of leading or trailing zeros is not applicable to DegreesMinutesSeconds angles format
422
                        string f = "0." + new string('0', this.AngularDecimalPlaces - 4);
×
423
                        return string.Format(numberFormat, "{0}" + this.DegreesSymbol + "{1}" + this.MinutesSymbol + "{2}" + this.SecondsSymbol, (int)degrees, (int)minutes, seconds.ToString(f, numberFormat));
×
UNCOV
424
                }
×
425

426
                /// <summary>
427
                /// Converts a value into its feet and decimal inches string representation.
428
                /// </summary>
429
                /// <param name="value">Must be in inches.</param>
430
                /// <returns>A string that represents the value in feet and decimal inches.</returns>
431
                public string ToEngineering(double value)
432
                {
×
433
                        NumberFormatInfo numberFormat = new NumberFormatInfo
×
434
                        {
×
435
                                NumberDecimalSeparator = this.DecimalSeparator
×
436
                        };
×
437
                        int feet = (int)(value / 12);
×
438
                        double inches = value - 12 * feet;
×
439

440
                        if (MathHelper.IsZero(inches))
×
441
                        {
×
442
                                if (feet == 0)
×
443
                                {
×
444
                                        if (this.SuppressZeroFeet)
×
445
                                        {
×
446
                                                return string.Format("0{0}", this.InchesSymbol);
×
447
                                        }
448

449
                                        if (this.SuppressZeroInches)
×
450
                                        {
×
451
                                                return string.Format("0{0}", this.FeetSymbol);
×
452
                                        }
453
                                        return string.Format("0{0}{1}0{2}", this.FeetSymbol, this.FeetInchesSeparator, this.InchesSymbol);
×
454
                                }
455

456
                                if (this.SuppressZeroInches)
×
457
                                {
×
458
                                        return string.Format("{0}{1}", feet, this.FeetSymbol);
×
459
                                }
460

461
                                return string.Format("{0}{1}{2}0{3}", feet, this.FeetSymbol, this.FeetInchesSeparator, this.InchesSymbol);
×
462
                        }
463

464
                        string inchesDec = inches.ToString(this.GetZeroHandlingFormat(), numberFormat);
×
465
                        if (feet == 0)
×
466
                        {
×
467
                                if (this.SuppressZeroFeet)
×
468
                                {
×
469
                                        return string.Format("{0}{1}", inches, this.InchesSymbol);
×
470
                                }
471

472
                                return string.Format("0{0}{1}{2}{3}", this.FeetSymbol, this.FeetInchesSeparator, inchesDec, this.InchesSymbol);
×
473
                        }
474
                        return string.Format("{0}{1}{2}{3}{4}", feet, this.FeetSymbol, this.FeetInchesSeparator, inchesDec, this.InchesSymbol);
×
475
                }
×
476

477
                /// <summary>
478
                /// Converts a value into its fractional string representation.
479
                /// </summary>
480
                /// <param name="value"></param>
481
                /// <returns>A string that represents the value in fractional units.</returns>
482
                public string ToFractional(double value)
UNCOV
483
                {
×
UNCOV
484
                        int num = (int)value;
×
UNCOV
485
                        getFraction(value, (short)Math.Pow(2, this.LinearDecimalPlaces), out int numerator, out int denominator);
×
UNCOV
486
                        if (numerator == 0)
×
487
                        {
×
488
                                return string.Format("{0}", (int)value);
×
489
                        }
490

UNCOV
491
                        string text = string.Empty;
×
UNCOV
492
                        switch (this.FractionType)
×
493
                        {
494
                                case FractionFormat.Diagonal:
495
                                        text = $"\\A1;{num}{{\\H{this.FractionHeightScale}x;\\S{numerator}#{denominator};}}";
×
496
                                        break;
×
497

498
                                case FractionFormat.Horizontal:
499
                                        text = $"\\A1;{num}{{\\H{this.FractionHeightScale}x;\\S{numerator}/{denominator};}}";
×
500
                                        break;
×
501

502
                                case FractionFormat.None:
UNCOV
503
                                        string prefix = num == 0 ? string.Empty : $"{num.ToString()} ";
×
UNCOV
504
                                        text = $"{prefix}{numerator}/{denominator}";
×
UNCOV
505
                                        break;
×
506
                        }
UNCOV
507
                        return text;
×
UNCOV
508
                }
×
509

510
                /// <summary>
511
                /// Converts an angle value in radians into its gradians string representation.
512
                /// </summary>
513
                /// <param name="angle">The angle value in radians.</param>
514
                /// <returns>A string that represents the angle in gradians.</returns>
515
                public string ToGradians(double angle)
UNCOV
516
                {
×
UNCOV
517
                        NumberFormatInfo numberFormat = new NumberFormatInfo
×
UNCOV
518
                        {
×
UNCOV
519
                                NumberDecimalSeparator = this.DecimalSeparator
×
UNCOV
520
                        };
×
521

UNCOV
522
                        return (MathHelper.RadToGrad(angle)).ToString(GetZeroHandlingFormat(true), numberFormat) + this.GradiansSymbol;
×
UNCOV
523
                }
×
524

525
                /// <summary>
526
                /// Converts an angle value in radians into its string representation.
527
                /// </summary>
528
                /// <param name="angle">The angle value in radians.</param>
529
                /// <returns>A string that represents the angle in radians.</returns>
530
                public string ToRadians(double angle)
UNCOV
531
                {
×
UNCOV
532
                        NumberFormatInfo numberFormat = new NumberFormatInfo
×
UNCOV
533
                        {
×
UNCOV
534
                                NumberDecimalSeparator = this.DecimalSeparator
×
UNCOV
535
                        };
×
UNCOV
536
                        return angle.ToString(GetZeroHandlingFormat(true), numberFormat) + this.RadiansSymbol;
×
UNCOV
537
                }
×
538

539
                /// <summary>
540
                /// Converts a value into its scientific string representation.
541
                /// </summary>
542
                /// <param name="value">The length value.</param>
543
                /// <returns>A string that represents the length in scientific units.</returns>
544
                public string ToScientific(double value)
UNCOV
545
                {
×
UNCOV
546
                        return value.ToString($"{this.GetZeroHandlingFormat()}E+00");
×
UNCOV
547
                }
×
548

549
                private static void getFraction(double number, int precision, out int numerator, out int denominator)
UNCOV
550
                {
×
UNCOV
551
                        numerator = Convert.ToInt32((number - (int)number) * precision);
×
UNCOV
552
                        int commonFactor = getGCD(numerator, precision);
×
UNCOV
553
                        if (commonFactor <= 0)
×
554
                        {
×
555
                                commonFactor = 1;
×
556
                        }
×
UNCOV
557
                        numerator = numerator / commonFactor;
×
UNCOV
558
                        denominator = precision / commonFactor;
×
UNCOV
559
                }
×
560

561
                private static int getGCD(int number1, int number2)
UNCOV
562
                {
×
UNCOV
563
                        int a = number1;
×
UNCOV
564
                        int b = number2;
×
UNCOV
565
                        while (b != 0)
×
UNCOV
566
                        {
×
UNCOV
567
                                int count = a % b;
×
UNCOV
568
                                a = b;
×
UNCOV
569
                                b = count;
×
UNCOV
570
                        }
×
UNCOV
571
                        return a;
×
UNCOV
572
                }
×
573
        }
574
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc