Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6334289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:37:52+00:00 2026-05-24T18:37:52+00:00

I am trying to re-write a piece of code which was in Java to

  • 0

I am trying to re-write a piece of code which was in Java to C#, and I ran into a problem, basically I am creating a method which returns a string, but the string returned from c# and java is not the same, therefore the code is fauly. One problem is the following code,

I have this Java Code:

Double localDouble1 = new Double(d1 / 100.0D);
int l = localDouble1.intValue();

And I want to re-write it in C#, I have tried

Double localDouble1 = d1 / 100.0D;
int l = Convert.ToInt32(localDouble1);

It compiles and works, but the result is different, in my particular scenario, the Java int l variable contains 0, and the c# one returns 1.

Is there a better method to achieve what I need to do, the same as in Java.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T18:37:54+00:00Added an answer on May 24, 2026 at 6:37 pm

    Convert.ToInt32(double) rounds to the nearest integer. intValue() doesn’t – it truncates, just as a cast does (as documented).

    Just cast instead:

    int l = (int) localDouble1;
    

    (Also try to avoid names like l which look like 1 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am trying to write a piece of code which will allows the user to
I was trying to write a piece of Java code to read each line
I'm trying to write a piece of code that will do the following: Take
Begginer's question. I'm trying to write small piece of code in Visual Studio (VB.net)
I'm trying to write a unit test for a piece of code that generates
I am trying to write a simple piece of Jquery in which the script
I'm trying to write a piece of code in python to get command-line options
I am trying to write a piece of code that can parse any xml
I am currently trying to write some code which is going to send a
Im trying to write a piece of code to set the image of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.