473,698 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

truncating decimal on numbers

cj
I want 7 * .105263 to result in an int32 value of 0. and 7 * .189021 to
result in an int32 value of 1.

I don't want to round. How can I just drop the decimal places?
Nov 8 '06 #1
3 1283
cj
never mind--I knew as soon as I asked I'd find the answer. Sometimes
I'm tempted to ask just because I know I'll find the answer as soon as I
hit send.

Int or Fix is what I wanted.
cj wrote:
I want 7 * .105263 to result in an int32 value of 0. and 7 * .189021 to
result in an int32 value of 1.

I don't want to round. How can I just drop the decimal places?
Nov 8 '06 #2
"cj" <cj@nospam.nosp amschrieb:
>I want 7 * .105263 to result in an int32 value of 0. and 7 * .189021 to
result in an int32 value of 1.

I don't want to round. How can I just drop the decimal places?
Check out 'Fix', 'Int', and 'Math.Floor' and 'Math.Ceil'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 8 '06 #3
CJ,

You can always use it as string and than cut the decimals you don't want
using the IProvider from ToSring. Is as well an easy way to round in any way
you want.

CJM

"cj" <cj@nospam.nosp amschreef in bericht
news:O8******** ******@TK2MSFTN GP02.phx.gbl...
>I want 7 * .105263 to result in an int32 value of 0. and 7 * .189021 to
result in an int32 value of 1.

I don't want to round. How can I just drop the decimal places?

Nov 9 '06 #4

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

Similar topics

21
4520
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
17
6143
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...
2
3466
by: Steve Summit | last post by:
-----BEGIN PGP SIGNED MESSAGE----- It's often explained that the reason for some of the imprecision in C's definition is so that C can be implemented on different kinds of machines -- say, those with 2's complement, 1's complement, or sign-magnitude arithmetic. But the followup remark is sometimes also made that the choice of arithmetic isn't completely unconstrained, since the bitwise operators seem to presume a base-2 machine.
5
5428
by: VISHNU VARDHAN REDDY UNDYALA | last post by:
Hello, Can someone over here help me in truncating a float variable. I mean if PI=3.14159 ...How can I get to read the first two or first three decimal values with out rounding them. Any suggestions are appreciated. I am BEGINNER TO C PROGRAAMING. Thanks
5
23951
by: GaryB | last post by:
I have a database field that is the product of a multiply in a sql statement and it sometimes has 5 or more decimal places. I want to truncate beyond the 2nd decimal place(###.##). I figured a Ctype to a decimal value would do that but the four decimal places remain. I found a truncate function but it only truncates to whole numbers. how can I do the truncation? Thanks, G
11
2246
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!
1
2128
by: sconnors | last post by:
I am currently working on an application that runs on Windows XP SP2 with .NET 2.0, Linux 2.4.19-16mdkenterprise and Solaris 5.9. The language is C++. When I compare the output numbers, Windows rounds the numbers up (for example: 13030.65 becomes 13030.7 - precision is 6) and in Linux/Solaris the number is rounded down or more likely truncated (for example: 13030.65 becomes 13030.6). I can set the precision on the ostream or output file...
4
7763
by: Todd | last post by:
I have a function that takes a double and truncates it to a specified number of decimal places. I've found that I have to add a small number to the input value otherwise I get errors due to the way floating points work. double TruncateToDigits(double dValue, int iDigitsToRightOfDecimal) { double dEpsilon = 1e-8; // high limit, about 100,000,000 for this epsilon (1e-8) // low limit, about 7 decimal places for this epsilon (1e-8)
1
2644
by: Serenityquinn15 | last post by:
Hi! I have a little trouble about in truncating numbers. What i want to do is to get the two decimal places. here's the example: when i try to get the half of 20500.39 it shows like this:10250.195 but what i want to see is 10250.19 only. another one is 20500.42, it shows like this: 10250.2 which in real, it must be 10250.21.
0
9161
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
8897
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
7732
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...
0
5860
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();...
0
4370
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3050
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 we have to send another system
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2006
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.