Hi
I'm working with Datagrid containg decimal (editable) numbers. The
user-entered numbers are read by decimal.Parse() method. However, Datagrid
formats some decimals as "1", but some as (eg) "1.00" - depends on what the
user had entered. The page has DISABLED viewstate.
So, let someone explain me why the number 1 is not the same as 1.0 or 1.000?
I cannot find any property to set the precision.
The number of decimal digits can be different in different rows, so no
static format option can be used. Currently the only option to get correct
formatting is (a bit stupid) construction like this:
((decimal)DataB inder.Eval(Cont ainer.DataItem, "Quantity")).To String("F" +
((int)DataBinde r.Eval(Containe r.DataItem, "DecimalPlaces" )).ToString()
Regards. 2 6502
Hi, Piotr,
"Piotr" <an******@false .account.pl> wrote in message
news:c4******** **@atlantis.new s.tpi.pl... Hi
I'm working with Datagrid containg decimal (editable) numbers. The user-entered numbers are read by decimal.Parse() method. However, Datagrid formats some decimals as "1", but some as (eg) "1.00" - depends on what
the user had entered. The page has DISABLED viewstate.
So, let someone explain me why the number 1 is not the same as 1.0 or
1.000?
There is no difference *between the values* indeed. The difference is in the
way these are stored.
1 is stored as 1 / 10^0
1.0 is stored as 10 / 10^1
1.000 is stored as 1000 / 10^3
See: http://msdn.microsoft.com/library/en...ClassTopic.asp
This code illustrates it:
decimal d = decimal.One;
for(int i = 0; i < 20;i++)
{
d = -decimal.Parse(d .ToString("F" + i));
int[] strip = decimal.GetBits (d);
ulong value = Convert.ToUInt6 4(
((uint)strip[1]).ToString("x") +
((uint)strip[0]).ToString("x") , 16);
Console.WriteLi ne(
"{0,-22} = {1,-22} / 10^{2,-3} {3}",
d,
value,
(strip[3] & 0xFF0000) >> 16,
(((strip[3] >> 31) & 1) > 0 ? "Negative" : "Positive") );
}
See the topic on GetBits method: http://msdn.microsoft.com/library/en...tBitsTopic.asp
I cannot find any property to set the precision.
The number of decimal digits can be different in different rows, so no static format option can be used. Currently the only option to get correct formatting is (a bit stupid) construction like this: ((decimal)DataB inder.Eval(Cont ainer.DataItem, "Quantity")).To String("F" + ((int)DataBinde r.Eval(Containe r.DataItem, "DecimalPlaces" )).ToString()
You can try setting the DataFormatStrin g property alternatively:
"F" + DataBinder.Eval (Container.Data Item, "DecimalPlaces" ).ToString()
should be fine.
Hope this helps
Martin Regards.
Hi, Piotr,
"Piotr" <an******@false .account.pl> wrote in message
news:c4******** **@atlantis.new s.tpi.pl... Hi
I'm working with Datagrid containg decimal (editable) numbers. The user-entered numbers are read by decimal.Parse() method. However, Datagrid formats some decimals as "1", but some as (eg) "1.00" - depends on what
the user had entered. The page has DISABLED viewstate.
So, let someone explain me why the number 1 is not the same as 1.0 or
1.000?
There is no difference *between the values* indeed. The difference is in the
way these are stored.
1 is stored as 1 / 10^0
1.0 is stored as 10 / 10^1
1.000 is stored as 1000 / 10^3
See: http://msdn.microsoft.com/library/en...ClassTopic.asp
This code illustrates it:
decimal d = decimal.One;
for(int i = 0; i < 20;i++)
{
d = -decimal.Parse(d .ToString("F" + i));
int[] strip = decimal.GetBits (d);
ulong value = Convert.ToUInt6 4(
((uint)strip[1]).ToString("x") +
((uint)strip[0]).ToString("x") , 16);
Console.WriteLi ne(
"{0,-22} = {1,-22} / 10^{2,-3} {3}",
d,
value,
(strip[3] & 0xFF0000) >> 16,
(((strip[3] >> 31) & 1) > 0 ? "Negative" : "Positive") );
}
See the topic on GetBits method: http://msdn.microsoft.com/library/en...tBitsTopic.asp
I cannot find any property to set the precision.
The number of decimal digits can be different in different rows, so no static format option can be used. Currently the only option to get correct formatting is (a bit stupid) construction like this: ((decimal)DataB inder.Eval(Cont ainer.DataItem, "Quantity")).To String("F" + ((int)DataBinde r.Eval(Containe r.DataItem, "DecimalPlaces" )).ToString()
You can try setting the DataFormatStrin g property alternatively:
"F" + DataBinder.Eval (Container.Data Item, "DecimalPlaces" ).ToString()
should be fine.
Hope this helps
Martin Regards. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Batista, Facundo |
last post by:
Here I send it.
Suggestions and all kinds of recomendations are more than welcomed.
If it all goes ok, it'll be a PEP when I finish writing/modifying the code.
Thank you.
.. Facundo
|
by: John Bentley |
last post by:
John Bentley:
INTRO
The phrase "decimal number" within a programming context is ambiguous. It could
refer to the decimal datatype or the related but separate concept of a generic
decimal number. "Decimal Number" sometimes serves to distinguish Base 10
numbers, eg "15", from Base 2 numbers, Eg "1111". At other times "Decimal
Number" serves to differentiate a number from an integer. For the rest of this
post I shall only use either...
|
by: Peter Blatt |
last post by:
Does 5 represent the total numer of digits (including the fractional portion) or only the number of places
BEFORE the decimal point? Moreover does the number include the decimal point?
Are there differences between the databases servers ?
Peter
|
by: Tariq |
last post by:
I've a SQL view performing a number of very precise calculations ie.
495/(1.112 - (.00043499*((Col1 + Col2 + Col3))) + ( .00000055 * ((Col1
+ Col2 + Col3)) * ((Col1 + Col2 + Col3))) - (.00028826 * Col4))) -
450)/100
Obviously this sometimes causes a precision issues because the float
and real datatypes don't hold precise values... My problem is that
converting to the numeric or decimal datatype easily produces an error
if the...
|
by: cody |
last post by:
no this is no trollposting and please don't get it wrong but iam very
curious why people still use C instead of other languages especially C++.
i heard people say C++ is slower than C but i can't believe that. in pieces
of the application where speed really matters you can still use "normal"
functions or even static methods which is basically the same.
in C there arent the simplest things present like constants, each struct and
enum...
| |
by: nick |
last post by:
printf("%lf",3.25);
the result is 3.25000
i want the answer correct to 3 decimal places
What should i do?
thanks!
|
by: Paul Sullivan |
last post by:
decimal d;
d = 1.1M
OR
d= (decimal) 1.1
Discussioon
|
by: Pieter |
last post by:
Hi,
I'm having some troubles with my numeric-types in my VB.NET 2005
application, together with a SQL Server 2000.
- I first used Single in my application, and Decimal in my database. But a
Single with value 4.475 was converted to a Decimal with value
4.4749999999999996D. So after inserting and selecting it from the database I
got another value than the original!
|
by: Boot2TheHead |
last post by:
This one cost me a solid half hour yesterday. I'm wondering why on
earth the default precision for a decimal type is 18,0. Maybe I'm
mistaken. A decimal datatype sort of implies that you'd want something
after the decimal!
Question is, can I set this database-wide? Like all new decimal
datatypes have a precision of 12,6 or something like that? I haven't
seen anything about this in the googling I have done...
|
by: neha_chhatre |
last post by:
which is the best format specifier(data type) if i have to work with
decimal number.
also please tell me the syntax for truncating a decimal number
please reply as soon as possible
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |