473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

serializable double with precision


When I serialise an object I would like to have a double precision in
the "double" type :

My code:
private double _price = 100;
public double Price
(
get (return;)
set (_price = value;)
}

Serialize :

<price100 </ price>

And i want:

<price100.00 </ price>

How do ?

thanks
Feb 8 '08 #1
2 7048
Well, you could perhaps do it manually? I wouldn't do the entire
serialization yourself, but how about:

[XmlIgnore]
public double Price {...}

[XmlElement("Price")]
public string PriceString {
get {return (your expicit Price.ToString() or whatever);}
set {Price = double.Parse(value);}
}

If you do this, you may wish to explicitely use an invariant culture
in the ToString() / Format().

Also - if you are using data-contracts, note that you can happily make
PriceString private; if the intellisense annoys you can can use
[EditorBrowsable({blah}.Never)] to remove it from view.

Marc
Feb 8 '08 #2
Marc Gravell wrote:
Well, you could perhaps do it manually? I wouldn't do the entire
serialization yourself, but how about:

[XmlIgnore]
public double Price {...}

[XmlElement("Price")]
public string PriceString {
get {return (your expicit Price.ToString() or whatever);}
set {Price = double.Parse(value);}
}

If you do this, you may wish to explicitely use an invariant culture
in the ToString() / Format().

Also - if you are using data-contracts, note that you can happily make
PriceString private; if the intellisense annoys you can can use
[EditorBrowsable({blah}.Never)] to remove it from view.

Marc

it's perfect...
i use :
private double _paye = 0;
//[XmlElement(ElementName = "paye")]
[XmlIgnore]
public double Paye
{
get { return _paye; }
set { _paye = value; }
}
[XmlElement("paye")]
public string PayeString
{
get { return Paye.ToString("#0.00"); }
set { double.TryParse(value, out _paye); }
}
and i can continue to use my code ! (public object this[string index])
a minimum code change ! perfect !

great thanks for this tips !

Feb 13 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: DAVID SCHULMAN | last post by:
I've been trying to perform a calculation that has been running into an underflow (insufficient precision) problem in Microsoft Excel, which calculates using at most 15 significant digits. For this...
31
by: Bjørn Augestad | last post by:
Below is a program which converts a double to an integer in two different ways, giving me two different values for the int. The basic expression is 1.0 / (1.0 * 365.0) which should be 365, but one...
10
by: Bryan Parkoff | last post by:
The guideline says to use %f in printf() function using the keyword float and double. For example float a = 1.2345; double b = 5.166666667; printf("%.2f\n %f\n", a, b);
6
by: R.Biloti | last post by:
Hi folks I wrote the naive program to show up the unit roundoff (machine precision) for single and double precision: #include <stdio.h> int main (void) { double x;
60
by: Erick-> | last post by:
hi all... I've readed some lines about the difference between float and double data types... but, in the real world, which is the best? when should we use float or double?? thanks Erick
9
by: richard_lavoie | last post by:
Hi, I have something like this: vector<floatvec1; and I want to cast it, so I use vector vec2<double= static_cast< vector<double(vec1); I always become a error: syntax error before `>'...
29
by: Virtual_X | last post by:
As in IEEE754 double consist of sign bit 11 bits for exponent 52 bits for fraction i write this code to print double parts as it explained in ieee754 i want to know if the code contain any...
248
by: md | last post by:
Hi Does any body know, how to round a double value with a specific number of digits after the decimal points? A function like this: RoundMyDouble (double &value, short numberOfPrecisions) ...
0
by: Charles Coldwell | last post by:
James Kanze <james.kanze@gmail.comwrites: True, with some additional considerations. The commonly used IEEE 754 floating point formats are single precision: 32 bits including 1 sign bit, 23...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.