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

  • SEARCH
  • Home
  • 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 8613397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:51:57+00:00 2026-06-12T04:51:57+00:00

When I run the following code: public int[] finalResult = new int[dimension]; public float[]

  • 0

When I run the following code:

public int[] finalResult = new int[dimension];
public float[] calculatedValue = new float[dimension];
.....
.....
finalResult[i] = (int) Math.Floor(calculatedValue[i]);
Console.WriteLine( "calculated:" + calculatedValue[i] 
    +  " final:" + finalResult[i] 
    + "  test: " +(int) Math.Floor(calculatedValue[i]));

The output is:

calculated:-0.02043936 final:0 test:-1

Why is “final” different from “test” when they are generated from exactly the same code? Which one is wrong, and why?

even simpler, and smaller fragment

finalResult[i]=(int)Math.Floor(-3.0002);
Console.WriteLine( "final: "+ finalResult[i]+ " test:" +(int)Math.Floor(-3.0002));

output
final:0 test:-4

The remaining of the code is irrevelant as below proves
I tried the following lastly,

public int[] junkArray = new int[dimension];
junkArray[i]=(int)Math.Floor(-3.0002);  //Junk Array is only assigned here in whole code
Console.WriteLine( "final: "+ (int) junkArray[i]+ " test:" +(int)Math.Floor(-3.0002));

I get output as final:0 test:-4

  • 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-06-12T04:51:58+00:00Added an answer on June 12, 2026 at 4:51 am

    If I test the code

    var final = new int[1];
    var calc = new[] { -0.02043936f };
    final[0] = (int)Math.Floor(calc[0]);
    
    Console.WriteLine(
        "calc:{0} final:{1} test:{2}",
        calc[0],
        final[0],
        (int)Math.Floor(calc[0]));
    

    unsuprisingly I get the output

    calc:-0.02043936 final:-1 test:-1

    So, something else is wrong with your code.

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

Sidebar

Related Questions

I try to run the following code: public void Init(Url rootUrl) { var web
I run the following code from command line: public class MemoryTest { public static
I am trying to run the following simple code, public abstract class Shape{ abstract
Given the following code sample: public class WeirdStuff { public static int doSomething() {
consider the following code: public class SynchronizedCounter extends Thread { private int c =
I have a thread that executes the following code: public void run() { try
i have executed the following code public class Activity_Threads_Handler extends Activity { private int
The application will run fine unless I add the following code. public class TFView
I have the following code: public static void main(String[] args) { try { int
I have the following code public class Test { Lock lock = new ReentrantLock();

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.