473,659 Members | 2,671 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.Diagnost ics.Debug.Asser t(decimal.Trunc ate(this.Gesamt Preis*100)==thi s
..GesamtPreis*1 00);

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 1384

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

System.Diagnost ics.Debug.Asser t(decimal.Trunc ate(this.Gesamt Preis*100)==thi s
.GesamtPreis*10 0);

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******** ******@TK2MSFTN GP12.phx.gbl...
I want to do some validation of data field something like the following:

System.Diagnost ics.Debug.Asser t(decimal.Trunc ate(this.Gesamt Preis*100)==thi s
.GesamtPreis*10 0);

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*********@cu be.net> schrieb im Newsbeitrag
news:eP******** ******@tk2msftn gp13.phx.gbl...
"cody" <de********@gmx .de> wrote in
news:Ow******** ******@TK2MSFTN GP12.phx.gbl...
I want to do some validation of data field something like the following:

System.Diagnost ics.Debug.Asser t(decimal.Trunc ate(this.Gesamt Preis*100)==thi s .GesamtPreis*10 0);

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
6135
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...
5
1976
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 some Decimal values onto a binary file (or into a stream that writes into an array of bytes) and examine them.
687
23342
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...
1
1642
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 = 4; Power = -1; Power--) { Remainder = Decimal - (pow(2,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 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
28
5868
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places? ----------------------------------------------------------------------- When formatting money for example, to format 6.57634 to 6.58, 6.5 to 6.50, and 6 to 6.00? Rounding of x.xx5 is uncertain, as such numbers are not represented exactly. See section 4.7 for Rounding issues.
2
1285
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 didn't find anything that popped out, and I'm too tired to keep digging. I'm making a little program that is trying to do weird and sexy things by fully leveraging the power of all the built-in beauty of Python. I was trying to play around with the...
23
9770
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
5315
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 number text box, a numerator text box, and a denominator text box. I realize that this is probably the closest I'll get to having fractions displayed in VB, so that's no big deal. I'm able to simplify most numbers with some code I've written,...
0
8330
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,...
0
8850
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, 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...
1
8523
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8626
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 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...
0
7355
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, 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...
1
6178
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 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...
0
5649
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();...
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
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...

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.