473,394 Members | 1,916 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,394 software developers and data experts.

Displaying integer part of a decimal value

Hi,
Sorry if this is so basic but i wanted to know the correct way of
displaying a value's "only" integer part.

I mean; if i declare a value as integer which is actually a decimal
number, it returns upper value after .51 decimal part.

I mean;
Dim number as integer = 12.51 returns 13.

If i;
Dim number as integer = 12.49 returns 12 as well.

I want to return only the integer part (12) in every case without
depending on whatever decimal part is.

Thanks
Feb 13 '08 #1
6 12886

"kimiraikkonen" <ki*************@gmail.comkirjoitti viestissä
news:ab**********************************@l16g2000 hsh.googlegroups.com...
Hi,
Sorry if this is so basic but i wanted to know the correct way of
displaying a value's "only" integer part.

I mean; if i declare a value as integer which is actually a decimal
number, it returns upper value after .51 decimal part.

I mean;
Dim number as integer = 12.51 returns 13.

If i;
Dim number as integer = 12.49 returns 12 as well.

I want to return only the integer part (12) in every case without
depending on whatever decimal part is.

Thanks
Math.Floor for example.

-Teemu

Feb 13 '08 #2
"kimiraikkonen" <ki*************@gmail.comschrieb
Hi,
Sorry if this is so basic but i wanted to know the correct way of
displaying a value's "only" integer part.

I mean; if i declare a value as integer which is actually a decimal
number, it returns upper value after .51 decimal part.

I mean;
Dim number as integer = 12.51 returns 13.
Option Strict On?
Use
number = cint(int(12.51))
Armin
Feb 13 '08 #3
"kimiraikkonen" <ki*************@gmail.comschrieb:
Sorry if this is so basic but i wanted to know the correct way of
displaying a value's "only" integer part.
'Int', 'Fix', 'Math.Floor', depending on what you want.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Feb 13 '08 #4
On Feb 13, 7:26 pm, "Teemu" <tsir...@hotmail.comwrote:
"kimiraikkonen" <kimiraikkone...@gmail.comkirjoitti viestissänews:ab********************************** @l16g2000hsh.googlegroups.com...
Hi,
Sorry if this is so basic but i wanted to know the correct way of
displaying a value's "only" integer part.
I mean; if i declare a value as integer which is actually a decimal
number, it returns upper value after .51 decimal part.
I mean;
Dim number as integer = 12.51 returns 13.
If i;
Dim number as integer = 12.49 returns 12 as well.
I want to return only the integer part (12) in every case without
depending on whatever decimal part is.
Thanks

Math.Floor for example.

-Teemu
Thanks all. Much ways there were.
Feb 13 '08 #5
On Feb 13, 9:43 pm, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Feb 13, 7:26 pm, "Teemu" <tsir...@hotmail.comwrote:
"kimiraikkonen" <kimiraikkone...@gmail.comkirjoitti viestissänews:ab********************************** @l16g2000hsh.googlegroups.com...
Hi,
Sorry if this is so basic but i wanted to know the correct way of
displaying a value's "only" integer part.
I mean; if i declare a value as integer which is actually a decimal
number, it returns upper value after .51 decimal part.
I mean;
Dim number as integer = 12.51 returns 13.
If i;
Dim number as integer = 12.49 returns 12 as well.
I want to return only the integer part (12) in every case without
depending on whatever decimal part is.
Thanks
Math.Floor for example.
-Teemu

Thanks all. Much ways there were.
As last, i'd like to know how get these functions work with the value
in textbox?

if i type 12.51(dot) in textbox1 and use that code;
Dim number As Integer = TextBox1.Text
MsgBox(Math.Floor(number))

i get: 1251

and if i type 12,51 (comma) in textbox1 and use that code;
Dim number As Integer = TextBox1.Text
MsgBox(Math.Floor(number))

i get: 13 instead of 12

Behaviour is same also with FIX function...

Thanks!
Feb 13 '08 #6
"kimiraikkonen" <ki*************@gmail.comschrieb
Thanks Armin, a shorter way i thought :-)

If TextBox1.Text.Contains(".") = True Then
TextBox1.Text = TextBox1.Text.Replace(".", ",")
End If
You'll get an exception if you enter "1.234,56" and the "," is the
decimal seperator as soon as you try to convert it to a number because
two "," are not allowed.
Armin

Feb 13 '08 #7

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

Similar topics

4
by: Si | last post by:
Hi. After the prompt reply to my message yeasterday (Problem with Opera an IE), I have another newbie question. How do I separate the integer and decimal part of a number, ie. If I had...
16
by: Charles Kerekes | last post by:
Hello everyone, I am still learning C++, so I'm not sure what I'm trying to do is possible. Her is a simplified example: char Test = 'L'; cout << "Test Char as decimal: " << dec << Test <<...
9
by: Henrik | last post by:
In Java you can write something like this. Does anyone know how to do this in javascript? "byte b=Integer.parseInt(int value or String).byteValue;"
5
by: Michael Søndergaard | last post by:
I Pascal there are a function for retriving the fractional part of a real number (Frac), I can't find any in the dotnet framework. The function needs to remove the integer part and keep only the...
1
by: Microsoft News Group | last post by:
I am trying to make a column which is decimal format, convert nulls to a certain string such as "No Max". This is for a price range, and if they do not put a value in, a null value is put in...
1
by: jmarr02s | last post by:
I am trying to change my Amount column Data Type from Integer to Decimal (precision 9 digits, scale 3, that is 6 digits to the left of decimal and 3 digits to the right of decimal. Here is the...
18
by: Alex Vinokur | last post by:
Ho to get valid value of integer part of double _as int value_? Here is a program that demonstrate the problem. ------ foo.c ------ #include <stdio.h> #include <math.h> int main () {
2
karthickbabu
by: karthickbabu | last post by:
Hi In my application i want to convert integer to decimal. I get a input and using convert function to convert into decimal. But it shows as it self. My code like as below, Is any wrong in...
4
by: Zenoba | last post by:
i have written a code which yields a decimal value for example 7.23, but i need the value greater than this number i.e the number integer 8. Can anyone suggest a way to do this please? what should...
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
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...

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.