Last change
on this file since 4695 was
1958,
checked in by epitzer, 16 years ago
|
Updated handling of floating and fixed point numbers, faster and more accurate serialization and parsing. (#646)
|
File size:
1004 bytes
|
Line | |
---|
1 | using System;
|
---|
2 | using HeuristicLab.Persistence.Core;
|
---|
3 | using HeuristicLab.Persistence.Interfaces;
|
---|
4 | using System.Reflection;
|
---|
5 | using System.Globalization;
|
---|
6 |
|
---|
7 | namespace HeuristicLab.Persistence.Default.Xml.Primitive {
|
---|
8 |
|
---|
9 | public class Float2XmlSerializer : PrimitiveXmlSerializerBase<float> {
|
---|
10 |
|
---|
11 | public static float ParseG8(string s) {
|
---|
12 | float f;
|
---|
13 | if (float.TryParse(s,
|
---|
14 | NumberStyles.AllowDecimalPoint |
|
---|
15 | NumberStyles.AllowExponent |
|
---|
16 | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out f))
|
---|
17 | return f;
|
---|
18 | throw new FormatException(
|
---|
19 | String.Format("Invalid float G8 number format \"{0}\" could not be parsed", s));
|
---|
20 | }
|
---|
21 |
|
---|
22 | public static string FormatG8(float f) {
|
---|
23 | return f.ToString("g8", CultureInfo.InvariantCulture);
|
---|
24 | }
|
---|
25 |
|
---|
26 | public override XmlString Format(float f) {
|
---|
27 | return new XmlString(FormatG8(f));
|
---|
28 | }
|
---|
29 |
|
---|
30 | public override float Parse(XmlString t) {
|
---|
31 | return ParseG8(t.Data);
|
---|
32 | }
|
---|
33 | }
|
---|
34 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.