473,505 Members | 15,798 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to make a decimal a power of ten?

I want to do some validation of data field something like the following:

System.Diagnostics.Debug.Assert(decimal.Truncate(t his.GesamtPreis*100)==this
..GesamtPreis*100);

so that Iam sure that no more than a certain number of decimals are stored,
but I don't want to hardcode them I want that the user can set how many
decimals are stored?

I cannot use Math.Pow() since it works with double instead of decimal so I
have rounding errors.
Jul 21 '05 #1
3 1368

"cody" <de********@gmx.de> wrote in message
news:Ow**************@TK2MSFTNGP12.phx.gbl...
I want to do some validation of data field something like the following:

System.Diagnostics.Debug.Assert(decimal.Truncate(t his.GesamtPreis*100)==this
.GesamtPreis*100);

so that Iam sure that no more than a certain number of decimals are
stored,
but I don't want to hardcode them I want that the user can set how many
decimals are stored?

I cannot use Math.Pow() since it works with double instead of decimal so I
have rounding errors.

Compare the decimal to the result of Decimal.Round.

David
Jul 21 '05 #2
"cody" <de********@gmx.de> wrote in
news:Ow**************@TK2MSFTNGP12.phx.gbl...
I want to do some validation of data field something like the following:

System.Diagnostics.Debug.Assert(decimal.Truncate(t his.GesamtPreis*100)==this
.GesamtPreis*100);

so that Iam sure that no more than a certain number of decimals are
stored,
but I don't want to hardcode them I want that the user can set how many
decimals are stored?

I cannot use Math.Pow() since it works with double instead of decimal so I
have rounding errors.


Why don't you use "decimal.Round(x, NumberOfDigits) == x"? Wouldn't that do
what you want?

Niki
Jul 21 '05 #3
Yes that will do it!

"Niki Estner" <ni*********@cube.net> schrieb im Newsbeitrag
news:eP**************@tk2msftngp13.phx.gbl...
"cody" <de********@gmx.de> wrote in
news:Ow**************@TK2MSFTNGP12.phx.gbl...
I want to do some validation of data field something like the following:

System.Diagnostics.Debug.Assert(decimal.Truncate(t his.GesamtPreis*100)==this .GesamtPreis*100);

so that Iam sure that no more than a certain number of decimals are
stored,
but I don't want to hardcode them I want that the user can set how many
decimals are stored?

I cannot use Math.Pow() since it works with double instead of decimal so I have rounding errors.
Why don't you use "decimal.Round(x, NumberOfDigits) == x"? Wouldn't that

do what you want?

Niki

Jul 21 '05 #4

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

Similar topics

17
6102
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....
5
1964
by: Michael A. Covington | last post by:
Microsoft's documentation is a bit unclear, but is Decimal in fact a radix-100 (base-100) arithmetic data type (in which each byte ranges only from 0 to 99)? It should be straightforward to dump...
687
22815
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...
1
1634
by: lmh86 | last post by:
Should the following algorithm produce the binary equivalent of an inputed decimal value? ---------- cout << "Decimal value: "; cin >> Decimal; Binary = 0; Remainder = Decimal; for(Power =...
3
245
by: cody | last post by:
I want to do some validation of data field something like the following: System.Diagnostics.Debug.Assert(decimal.Truncate(this.GesamtPreis*100)==this ..GesamtPreis*100); so that Iam sure that...
28
5812
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
2
1275
by: MooMaster | last post by:
Hey guys, I'm trying to do some black magic voodoo and it's a little late, so forgive me if this question seems obvious or has been asked before. I tried doing a search on context objects and...
23
9746
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
10
5301
by: Jason | last post by:
I'm making a program that will convert decimal inputs (in this case, in inches) and output a fractional answer. At the moment, I'm only able to output the fractional answer in three parts: A whole...
0
7218
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
7103
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
7307
Oralloy
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,...
0
7478
tracyyun
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...
0
5614
agi2029
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,...
1
5035
isladogs
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...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1532
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.