Solved

VB.Net Stop ineger rounding

Posted on 2011-03-02
7
412 Views
Last Modified: 2012-05-11
Hey,

How do I stop an integer from rounding?
I have numbers set out as #.##, but it always rounds to just 1 number.

How do I stop this?

Thanks!
0
Comment
Question by:Letsgetcoding
7 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 250 total points
ID: 35017569
can u post the whole code?

i tried this and it didn;t round:

Dim s As String
        s = Format(0.15162342, "#.##") -->0.15

        s = Format(0.85162342, "#.##") --> 0.85
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 35017576
which value did u tried and was rounded to 1?
0
 

Author Comment

by:Letsgetcoding
ID: 35017604
Private HomepageFeature As Integer = 39
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35017977
You can't stop and Integer from rounding. An integer by definition is a whole (i.e. non-decimal) number. You need to change data type to a floating-point type if you want decimals.
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 35018013
39 is an integer type so how exactly it was rounded to 1?!?!?
i don't understand where the issue comes from, can u explain with code?
0
 
LVL 3

Expert Comment

by:MTroutwine
ID: 35018262
You can take look at this article: http://vbnotebookfor.net/2007/07/31/what-you-should-know-about-rounding-in-vbnet/


However, I have to agree with the other comments.  If you are using an Integer data type you will not have any floating point value.  You will need to choose a data type that supports floating points such as Decimal, Float, Double. etc.
0
 

Author Comment

by:Letsgetcoding
ID: 35018942
Have decided to go with using a string. I misunderstood what an integer was.

Sedgwick, the part of code I was referring to was = 1. I copied the =39 by mistake. Sorry for the confusion.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question