I have x as double, hh as int32
in VBA I can perfom hh=Int(x) (narrowing conversion but disallowed in .NET)
One example in .NET is hh = System.Convert.ToInt32(x)
Could I use IConvertible and how would I code this?
Which is the better method keeping in mind that I would also be coding
calculations in hours/minutes/seconds, degress/minutes/seconds, radians and
logarithms. I would not want to lose too much precision in my results.
Regards 4 1937
In .Net doubles are not precise, I recommend decimals. If you have option
strict enabled then:
Dim x a decimal, hh as integer
hh = ctype(int(x),integer)
or
hh = ctype(x,integer)
or
if not integer.tryparse(x,hh) then msgbox("Cannot parse.")
"Terry" <yo**********@REMOVETHISntlworld.comwrote in message
news:et**************@TK2MSFTNGP06.phx.gbl...
>I have x as double, hh as int32
in VBA I can perfom hh=Int(x) (narrowing conversion but disallowed in
.NET)
One example in .NET is hh = System.Convert.ToInt32(x)
Could I use IConvertible and how would I code this?
Which is the better method keeping in mind that I would also be coding
calculations in hours/minutes/seconds, degress/minutes/seconds, radians
and logarithms. I would not want to lose too much precision in my results.
Regards
Thanks for the quick reply Amdrit,
I'll see what results I get.
Regards
"AMDRIT" <am****@hotmail.comwrote in message
news:ey*************@TK2MSFTNGP04.phx.gbl...
In .Net doubles are not precise, I recommend decimals. If you have option
strict enabled then:
Dim x a decimal, hh as integer
hh = ctype(int(x),integer)
or
hh = ctype(x,integer)
or
if not integer.tryparse(x,hh) then msgbox("Cannot parse.")
"Terry" <yo**********@REMOVETHISntlworld.comwrote in message
news:et**************@TK2MSFTNGP06.phx.gbl...
>>I have x as double, hh as int32
in VBA I can perfom hh=Int(x) (narrowing conversion but disallowed in .NET)
One example in .NET is hh = System.Convert.ToInt32(x)
Could I use IConvertible and how would I code this?
Which is the better method keeping in mind that I would also be coding calculations in hours/minutes/seconds, degress/minutes/seconds, radians and logarithms. I would not want to lose too much precision in my results.
Regards
"Terry" <yo**********@REMOVETHISntlworld.comschrieb:
>I have x as double, hh as int32
in VBA I can perfom hh=Int(x) (narrowing conversion but disallowed in
.NET)
One example in .NET is hh = System.Convert.ToInt32(x)
Could I use IConvertible and how would I code this?
Which is the better method keeping in mind that I would also be coding
calculations in hours/minutes/seconds, degress/minutes/seconds, radians
and logarithms. I would not want to lose too much precision in my results.
Check out 'CInt' too, which is maybe what you are looking for.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
OK thanks for that one.
Regards
Terry
"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:uk**************@TK2MSFTNGP06.phx.gbl...
"Terry" <yo**********@REMOVETHISntlworld.comschrieb:
>>I have x as double, hh as int32
in VBA I can perfom hh=Int(x) (narrowing conversion but disallowed in .NET)
One example in .NET is hh = System.Convert.ToInt32(x)
Could I use IConvertible and how would I code this?
Which is the better method keeping in mind that I would also be coding calculations in hours/minutes/seconds, degress/minutes/seconds, radians and logarithms. I would not want to lose too much precision in my results.
Check out 'CInt' too, which is maybe what you are looking for.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Erik Frey |
last post by:
Hello,
Say I have the following two classes:
class Base
{
}
class Inherited : Base
{
|
by: Aaron Queenan |
last post by:
Given the classes:
class Class
{
public static implicit operator int(Class c)
{
return 0;
}
}
class Holder
|
by: Codemonkey |
last post by:
Hi,
Sorry for a stupid question, but is it possible to do a narrowing conversion
with an object array with Option Strict On in VB?
E.g:
------------------
Dim aBase as Base() = {New...
|
by: rawCoder |
last post by:
Hi,
Just wanted to know if there is any speed difference between
VB conversion Keywords like CInt, Clng, CStr, CDbl, CBool etc.
..NETs Convert.To<...> methods.
And which is better to be...
|
by: Bill Nguyen |
last post by:
What do I need to do to add a row to a table with single column? I got the
"mnarrowing conversion" ewrror mesage.
Thanks
Bill
-----------------
| |
by: Pavils Jurjans |
last post by:
Hello,
I am somewhat lost in the implicit/expicit possible/impossible type casting
in C#...
I need to write a class, which among other things, must have wat to read a
numeric value type, and...
|
by: jason |
last post by:
Since going to framework 2.0 from 1.1, I'm getting error:
Overload resolution failed because no accessible 'New' can be called
without a narrowing conversion:
On line:
Dim LogInfo As New...
|
by: jaime |
last post by:
Hi all.
Apologies, since this is more a tool question, than strictly a language
question, but hey, it seemed like an appropriate place to ask...
I'm a c newbie (and have been now for about 6...
|
by: =?Utf-8?B?QU1lcmNlcg==?= |
last post by:
I have a strange situation with vb 2005 regarding option strict that looks
like a compiler bug to me. Consider:
Dim f1 As New Font("Arial", 8.25)
Dim f2 As New Font("Arial", 8.25,...
|
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...
|
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,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
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: 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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |