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

DomCR / ACadSharp / 20916316270

12 Jan 2026 10:39AM UTC coverage: 77.059% (-0.02%) from 77.082%
20916316270

push

github

DomCR
Merge branch 'master' of https://github.com/DomCR/ACadSharp

7919 of 11129 branches covered (71.16%)

Branch coverage included in aggregate %.

13 of 13 new or added lines in 3 files covered. (100.0%)

98 existing lines in 4 files now uncovered.

28849 of 36585 relevant lines covered (78.85%)

149607.99 hits per line

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

50.79
/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
                {
19
                        get { return this._angularDecimalPlaces; }
57✔
20
                        set
21
                        {
111✔
22
                                if (value < 0)
111!
23
                                {
×
24
                                        throw new ArgumentOutOfRangeException(nameof(value), value, "The number of decimal places must be equals or greater than zero.");
×
25
                                }
26
                                this._angularDecimalPlaces = value;
111✔
27
                        }
111✔
28
                }
29

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

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

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

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

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

55
                /// <summary>
56
                /// Gets or sets the scale of fractions relative to dimension text height.
57
                /// </summary>
58
                public double FractionHeightScale
59
                {
60
                        get { return this._fractionHeightScale; }
3✔
61
                        set
62
                        {
111✔
63
                                if (value <= 0)
111!
64
                                {
×
65
                                        throw new ArgumentOutOfRangeException(nameof(value), value, "The fraction height scale must be greater than zero.");
×
66
                                }
67
                                this._fractionHeightScale = value;
111✔
68
                        }
111✔
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>
79
                public FractionFormat FractionType { get; set; }
226✔
80

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

86
                /// <summary>
87
                /// Gets or set the inches symbol.
88
                /// </summary>
89
                public string InchesSymbol { get; set; }
113✔
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
                {
99
                        get { return this._linearDecimalPlaces; }
288✔
100
                        set
101
                        {
115✔
102
                                if (value < 0)
115!
103
                                {
×
104
                                        throw new ArgumentOutOfRangeException(nameof(value), value, "The number of decimal places must be equals or greater than zero.");
×
105
                                }
106
                                this._linearDecimalPlaces = value;
115✔
107
                        }
115✔
108
                }
109

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

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

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

125
                /// <summary>
126
                /// Gets or set the angle seconds symbol.
127
                /// </summary>
128
                public string SecondsSymbol { get; set; }
112✔
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
184
                        {
1✔
185
                                return this.LinearZeroHandling == ZeroHandling.SuppressZeroFeetAndInches
1!
186
                                        || this.LinearZeroHandling == ZeroHandling.SuppressZeroFeetShowZeroInches;
1✔
187
                        }
1✔
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>
211
                public UnitStyleFormat()
112✔
212
                {
112✔
213
                        this._linearDecimalPlaces = 2;
112✔
214
                        this._angularDecimalPlaces = 0;
112✔
215
                        this.DecimalSeparator = ".";
112✔
216
                        this.FeetInchesSeparator = "-";
112✔
217
                        this.DegreesSymbol = "°";
112✔
218
                        this.MinutesSymbol = "\'";
112✔
219
                        this.SecondsSymbol = "\"";
112✔
220
                        this.RadiansSymbol = "r";
112✔
221
                        this.GradiansSymbol = "g";
112✔
222
                        this.FeetSymbol = "\'";
112✔
223
                        this.InchesSymbol = "\"";
112✔
224
                        this._fractionHeightScale = 1.0;
112✔
225
                        this.FractionType = FractionFormat.Horizontal;
112✔
226
                }
112✔
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)
234
                {
111✔
235
                        short decimalPlaces;
236
                        ZeroHandling handling;
237

238
                        if (isAngular)
111✔
239
                        {
18✔
240
                                handling = this.AngularZeroHandling;
18✔
241
                                decimalPlaces = this.AngularDecimalPlaces;
18✔
242
                        }
18✔
243
                        else
244
                        {
93✔
245
                                handling = this.LinearZeroHandling;
93✔
246
                                decimalPlaces = this.LinearDecimalPlaces;
93✔
247
                        }
93✔
248

249
                        char leading = handling == ZeroHandling.SuppressDecimalLeadingZeroes
111✔
250
                                   || handling == ZeroHandling.SuppressDecimalLeadingAndTrailingZeroes ?
111✔
251
                                   '#' : '0';
111✔
252

253
                        char trailing = handling == ZeroHandling.SuppressDecimalTrailingZeroes
111✔
254
                           || handling == ZeroHandling.SuppressDecimalLeadingAndTrailingZeroes ?
111✔
255
                           '#' : '0';
111✔
256

257
                        StringBuilder zeroes = new();
111✔
258

259
                        zeroes.Append(leading);
111✔
260
                        zeroes.Append(".");
111✔
261

262
                        for (int i = 0; i < decimalPlaces; i++)
620✔
263
                        {
199✔
264
                                zeroes.Append(trailing);
199✔
265
                        }
199✔
266

267
                        return zeroes.ToString();
111✔
268
                }
111✔
269

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

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

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

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

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

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

306
                        getFraction(inchesDec, (short)Math.Pow(2, this.LinearDecimalPlaces), out int numerator, out int denominator);
1✔
307

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

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

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

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

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

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

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

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

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

364
                                case FractionFormat.Horizontal:
365
                                        text = $"\\A1;{feetStr}{inches}{{\\H{this.FractionHeightScale}x;\\S{numerator}/{denominator};}}{this.InchesSymbol}";
1✔
366
                                        break;
1✔
367

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

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

388
                        return value.ToString(this.GetZeroHandlingFormat(isAngular), numberFormat);
88✔
389
                }
88✔
390

391
                /// <summary>
392
                /// Converts an angle value in degrees string representation.
393
                /// </summary>
394
                /// <param name="angle">Angle value in radians.</param>
395
                /// <returns>A string that represents the value in degrees</returns>
396
                public string ToDegrees(double angle)
397
                {
13✔
398
                        double degrees = MathHelper.RadToDeg(angle);
13✔
399
                        NumberFormatInfo numberFormat = new NumberFormatInfo
13✔
400
                        {
13✔
401
                                NumberDecimalSeparator = this.DecimalSeparator
13✔
402
                        };
13✔
403
                        return degrees.ToString(GetZeroHandlingFormat(isAngular: true), numberFormat) + this.DegreesSymbol;
13✔
404
                }
13✔
405

406
                /// <summary>
407
                /// Converts an angle value in degrees into its degrees, minutes and seconds string representation.
408
                /// </summary>
409
                /// <param name="angle">Angle value in radians.</param>
410
                /// <returns>A string that represents the value in degrees, minutes and seconds</returns>
411
                public string ToDegreesMinutesSeconds(double angle)
412
                {
1✔
413
                        double degrees = MathHelper.RadToDeg(angle);
1✔
414
                        double minutes = (degrees - (int)degrees) * 60;
1✔
415
                        double seconds = (minutes - (int)minutes) * 60;
1✔
416

417
                        NumberFormatInfo numberFormat = new NumberFormatInfo
1✔
418
                        {
1✔
419
                                NumberDecimalSeparator = this.DecimalSeparator
1✔
420
                        };
1✔
421

422
                        if (this.AngularDecimalPlaces == 0)
1!
423
                        {
1✔
424
                                return string.Format(numberFormat, "{0}" + this.DegreesSymbol, (int)Math.Round(degrees, 0));
1✔
425
                        }
426

UNCOV
427
                        if (this.AngularDecimalPlaces == 1 || this.AngularDecimalPlaces == 2)
×
UNCOV
428
                        {
×
UNCOV
429
                                return string.Format(numberFormat, "{0}" + this.DegreesSymbol + "{1}" + this.MinutesSymbol, (int)degrees, (int)Math.Round(minutes, 0));
×
430
                        }
431

UNCOV
432
                        if (this.AngularDecimalPlaces == 3 || this.AngularDecimalPlaces == 4)
×
UNCOV
433
                        {
×
UNCOV
434
                                return string.Format(numberFormat, "{0}" + this.DegreesSymbol + "{1}" + this.MinutesSymbol + "{2}" + this.SecondsSymbol, (int)degrees, (int)minutes, (int)Math.Round(seconds, 0));
×
435
                        }
436

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

442
                /// <summary>
443
                /// Converts a value into its feet and decimal inches string representation.
444
                /// </summary>
445
                /// <param name="value">Must be in inches.</param>
446
                /// <returns>A string that represents the value in feet and decimal inches.</returns>
447
                public string ToEngineering(double value)
448
                {
×
449
                        NumberFormatInfo numberFormat = new NumberFormatInfo
×
450
                        {
×
UNCOV
451
                                NumberDecimalSeparator = this.DecimalSeparator
×
UNCOV
452
                        };
×
UNCOV
453
                        int feet = (int)(value / 12);
×
454
                        double inches = value - 12 * feet;
×
455

UNCOV
456
                        if (MathHelper.IsZero(inches))
×
UNCOV
457
                        {
×
UNCOV
458
                                if (feet == 0)
×
UNCOV
459
                                {
×
UNCOV
460
                                        if (this.SuppressZeroFeet)
×
UNCOV
461
                                        {
×
UNCOV
462
                                                return string.Format("0{0}", this.InchesSymbol);
×
463
                                        }
464

465
                                        if (this.SuppressZeroInches)
×
466
                                        {
×
467
                                                return string.Format("0{0}", this.FeetSymbol);
×
468
                                        }
469
                                        return string.Format("0{0}{1}0{2}", this.FeetSymbol, this.FeetInchesSeparator, this.InchesSymbol);
×
470
                                }
471

472
                                if (this.SuppressZeroInches)
×
473
                                {
×
474
                                        return string.Format("{0}{1}", feet, this.FeetSymbol);
×
475
                                }
476

477
                                return string.Format("{0}{1}{2}0{3}", feet, this.FeetSymbol, this.FeetInchesSeparator, this.InchesSymbol);
×
478
                        }
479

UNCOV
480
                        string inchesDec = inches.ToString(this.GetZeroHandlingFormat(), numberFormat);
×
481
                        if (feet == 0)
×
482
                        {
×
483
                                if (this.SuppressZeroFeet)
×
UNCOV
484
                                {
×
485
                                        return string.Format("{0}{1}", inches, this.InchesSymbol);
×
486
                                }
487

488
                                return string.Format("0{0}{1}{2}{3}", this.FeetSymbol, this.FeetInchesSeparator, inchesDec, this.InchesSymbol);
×
489
                        }
490
                        return string.Format("{0}{1}{2}{3}{4}", feet, this.FeetSymbol, this.FeetInchesSeparator, inchesDec, this.InchesSymbol);
×
UNCOV
491
                }
×
492

493
                /// <summary>
494
                /// Converts a value into its fractional string representation.
495
                /// </summary>
496
                /// <param name="value"></param>
497
                /// <returns>A string that represents the value in fractional units.</returns>
498
                public string ToFractional(double value)
499
                {
2✔
500
                        int num = (int)value;
2✔
501
                        getFraction(value, (short)Math.Pow(2, this.LinearDecimalPlaces), out int numerator, out int denominator);
2✔
502
                        if (numerator == 0)
2!
UNCOV
503
                        {
×
504
                                return string.Format("{0}", (int)value);
×
505
                        }
506

507
                        string text = string.Empty;
2✔
508
                        switch (this.FractionType)
2!
509
                        {
510
                                case FractionFormat.Diagonal:
UNCOV
511
                                        text = $"\\A1;{num}{{\\H{this.FractionHeightScale}x;\\S{numerator}#{denominator};}}";
×
UNCOV
512
                                        break;
×
513

514
                                case FractionFormat.Horizontal:
UNCOV
515
                                        text = $"\\A1;{num}{{\\H{this.FractionHeightScale}x;\\S{numerator}/{denominator};}}";
×
UNCOV
516
                                        break;
×
517

518
                                case FractionFormat.None:
519
                                        string prefix = num == 0 ? string.Empty : $"{num.ToString()} ";
2✔
520
                                        text = $"{prefix}{numerator}/{denominator}";
2✔
521
                                        break;
2✔
522
                        }
523
                        return text;
2✔
524
                }
2✔
525

526
                /// <summary>
527
                /// Converts an angle value in radians into its gradians string representation.
528
                /// </summary>
529
                /// <param name="angle">The angle value in radians.</param>
530
                /// <returns>A string that represents the angle in gradians.</returns>
531
                public string ToGradians(double angle)
532
                {
2✔
533
                        NumberFormatInfo numberFormat = new NumberFormatInfo
2✔
534
                        {
2✔
535
                                NumberDecimalSeparator = this.DecimalSeparator
2✔
536
                        };
2✔
537

538
                        return (MathHelper.RadToGrad(angle)).ToString(GetZeroHandlingFormat(true), numberFormat) + this.GradiansSymbol;
2✔
539
                }
2✔
540

541
                /// <summary>
542
                /// Converts an angle value in radians into its string representation.
543
                /// </summary>
544
                /// <param name="angle">The angle value in radians.</param>
545
                /// <returns>A string that represents the angle in radians.</returns>
546
                public string ToRadians(double angle)
547
                {
3✔
548
                        NumberFormatInfo numberFormat = new NumberFormatInfo
3✔
549
                        {
3✔
550
                                NumberDecimalSeparator = this.DecimalSeparator
3✔
551
                        };
3✔
552
                        return angle.ToString(GetZeroHandlingFormat(true), numberFormat) + this.RadiansSymbol;
3✔
553
                }
3✔
554

555
                /// <summary>
556
                /// Converts a value into its scientific string representation.
557
                /// </summary>
558
                /// <param name="value">The length value.</param>
559
                /// <returns>A string that represents the length in scientific units.</returns>
560
                public string ToScientific(double value)
561
                {
1✔
562
                        return value.ToString($"{this.GetZeroHandlingFormat()}E+00");
1✔
563
                }
1✔
564

565
                private static void getFraction(double number, int precision, out int numerator, out int denominator)
566
                {
3✔
567
                        numerator = Convert.ToInt32((number - (int)number) * precision);
3✔
568
                        int commonFactor = getGCD(numerator, precision);
3✔
569
                        if (commonFactor <= 0)
3!
UNCOV
570
                        {
×
UNCOV
571
                                commonFactor = 1;
×
UNCOV
572
                        }
×
573
                        numerator = numerator / commonFactor;
3✔
574
                        denominator = precision / commonFactor;
3✔
575
                }
3✔
576

577
                private static int getGCD(int number1, int number2)
578
                {
3✔
579
                        int a = number1;
3✔
580
                        int b = number2;
3✔
581
                        while (b != 0)
9✔
582
                        {
6✔
583
                                int count = a % b;
6✔
584
                                a = b;
6✔
585
                                b = count;
6✔
586
                        }
6✔
587
                        return a;
3✔
588
                }
3✔
589
        }
590
}
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