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 920515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:43:38+00:00 2026-05-15T18:43:38+00:00

I have a problem with conversion from double to decimal: public class CartesianCoordinates {

  • 0

I have a problem with conversion from double to decimal:

 public class CartesianCoordinates
    {
        public int LatitudeHours { get; set;}
        public int LatitudeMinutes { get; set; }
        public int LatitudeSeconds { get; set; }
        public GeoDirectionLongtitude LongitudeDirection { get; set; }

        public int LongitudeHours { get; set; }
        public int LongitudeMinutes { get; set; }
        public int LongitudeSeconds { get; set; }
        public GeoDirectionLatitude LatitudeDirection { get; set; }
    }

public class DecimalCoordinates
    {
        public decimal Latitude { get; set; }
        public decimal Longitude { get; set; }
    }

CartesianCoordinates CartesianCoordinates=new CartesianCoordinates(){LatitudeHours =12,LatitudeMinutes =34,LatitudeSeconds=56 }

     converterDecimalCoordinates.Latitude = CartesianCoordinates.LatitudeHours + (CartesianCoordinates.LatitudeMinutes + (CartesianCoordinates.LatitudeSeconds / 60)) / 60;

Why I get 12 ? I want 12,55

  • 1 1 Answer
  • 1 View
  • 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-15T18:43:39+00:00Added an answer on May 15, 2026 at 6:43 pm

    As a byproduct of my discussion with David M and Daniel Brückner under this answer and the partially wrong statement by myself under this answer by Adam, it has become clear that, sorry to say, all answers are only partially correct. What is happening is this:

    // example (all  x, y, z ar ints):
    Decimal d = x + y + z / 60M;
    
    // is left to right evaluated as
    Decimal d = x + y + (((Decimal) z) / 60M);
    
    // when doing addition, this is what happens when you add integers and something else:
    Decimal d = x + y + (int) (((Decimal) z) / 60M);
    
    // which will yield a truncated result.
    

    The result is: that just adding a 60M or 60.0 to the whole statement, as has been suggested, will not (or may not) yield the wanted result, depending on execution order of the statement and/or the existence of addition / subtraction, as is the case in the OP’s question.

    To fix this, follow Adam’s advice and convert each addition / subtraction step to decimals, use decimals all along (not very clear) or place the calculation in a little function that takes decimals as parameters, forcing implicit conversion:

    Decimal GetDecimalLatitude(Decimal latitudeHours, Decimal latitudeMinutes, Decimal latitudeSeconds)
    {
        return latitudeHours + (latitudeMinutes + (latitudeSeconds / 60)) / 60;
    }
    

    which, as a bonus, is shorter and adds to readability. Call this with the following statement:

    converterDecimalCoordinates.Latitude = GetDecimalLatitude(
        CartesianCoordinates.LatitudeHours, 
        CartesianCoordinates.LatitudeMinutes,
        CartesianCoordinates.LatitudeSeconds);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got this problem: invalid conversion from ‘void*’ to ‘uint8_t*’ When doing this: int
I have those two classes ///////////BASE CLASS class Base{ public: Base(int = 0); ~Base();
I have problem with UIWebView delay when the load image from url. In my
I have problem with context menu. I have got: @Override public void onCreateContextMenu(ContextMenu menu,
I have a simple class Name: class Name { private: char nameStr[30]; public: Name(const
The problem I have is that I open an Image from a GUI using
I have the following problem: The library libopencv_java.so compiled from OpenCV 2.3.1 with NDK6
Although the situation of conversion from Double s to BigDecimal s has improved a
So here is my problem: I have the interface: public interface ICell<Feature> where Feature:
Consider MyClass.java: public class MyClass { public void firstfunction(double fwd[]) { fwd[0] = 42;

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.