Questions tagged [unit-conversion]

Code whose primary purpose is to convert quantities from one system of measurement to another

6
votes
3answers
2k views

Python 3 - simple temperature program version 1.3

Thank you to everyone for the feedback provided to the initial version of this program posted here. Please find below the newest version, revised based on the comments provided, for review and ...
14
votes
3answers
2k views

Python 3 - simple temperature program

I have been teaching myself Python (as well as Tkinter) and today one of the sites I was reading, asked us to write a program to covert one value from Fahrenheit to Celsius, once - an easy three line ...
4
votes
0answers
64 views

RGB to YCbCr conversion in Java

I found a Go language code to do RGB to YCbCr conversion from here! I ported it to Java: ...
5
votes
0answers
142 views

Converting between cooking measurements

I've made an Android app that converts between cooking measurements, taking into account the type of product you use (that way it can convert between mass and volume by using the density). What are ...
4
votes
1answer
60 views

Enum class for weight units

I have some enum classes for units, like Weight units (KG and LB). I am translating the code to Qt C++ from Java, and I'm wondering what the best way to do this is as enums cannot have constructors in ...
3
votes
1answer
231 views

Convert bitcoin value based on exchange rate from JSON API

I’m learning F# and trying to find a more ‘functional’ way to code a simple program that retrieves the price of BTC and calculates the EUR value of an amount of Bitcoin. ...
0
votes
1answer
50 views

Temperature and speed unit converter class in JS

This is what I came up with, but I'm not sure if: putting it in Class is the best approach multiple repeats (this.val etc.) are acceptable there is a better ...
3
votes
2answers
114 views

Asking 2 values, feet and inches, and it converts them to centimeters

I was doing an exercise in PHP, and it works perfectly, no problems. But I think that maybe I coded it so long, and I think it can be shorter than it is now, but I don't know how to make it shorter ...
3
votes
1answer
78 views

Temperature calculator in Rust

Just on a chapter 3 of Rust Book so not much good in Rust. so tried to implement a simple temprature calculator as suggest in this chapter. so i would like you guys to point anything you feel ...
2
votes
2answers
97 views

Calculator to add time intervals

I have written a little program that calculates the time by given strings. A time string in the context of this program consists of a number and a following letter that can be s, m, h, or d. You can ...
4
votes
1answer
131 views

Performing unit conversions using intermediate conversions

Challenge: Two input files are given The first contains |N| ratios in the form of two labels and a ratio: USD, GBP, 0.69 Meter, Yard, 1.09 YEN, EUR, 0.0077 GBP, YEN, 167.75 ...
6
votes
2answers
642 views

Fahrenheit and Celsius converter in Rust

I made a program that converts between Celsius and Fahrenheit. Is there any way that I could make this code more efficient and cleaner? ...
3
votes
3answers
107 views

Beginner radian/degree converter program

I'm a bit of a beginner when it comes to Java, and I created this small code to help me grasp a few small subjects. It allows its user to convert a radical to a degree measure and a degree measure to ...
7
votes
2answers
234 views

Unit conversion program into metre and stored input

I was curious as to how I'd be able to make this much clearer to read because from my perspective I understand what does what but how does it look to a third party? Also how are my object / method ...
3
votes
1answer
65 views

Temperature converter in Rust with input error handling

I started learning Rust a few hours ago with the Rust Book (2018 edition) and as part of one of the exercises decided to make a temperature converter. I wanted to make sure it handled all inputs ...
5
votes
2answers
102 views

Custom data type - “Binary” Float (0-1.0)

In my current game I have the need for values ranging from 0 to 1, or from -1 to 1. The values should never exceed this threshold, so instead of constantly validating the values I made a custom data ...
2
votes
0answers
47 views

SI type safe unit calculations (revised)

This is the continuation of the questions raised in this thread I did include the improvements that were mentioned but still feel like, I do more copies than I need to. Also I am unsure about the ...
4
votes
1answer
69 views

SI type safe unit calculations

I wrote a small type-rich MKS Unit system for the consistent and safe calculation of physical units in everyday use. I realized some operators' implementations via the Barton-Nackman trick while ...
1
vote
2answers
255 views

Unit of measure class for mass in java

I was looking at this answer on SO to handle units in java. The concept was interesting to me, except I didn't like that it had to be per object that had mass, instead of encapsulating a ...
3
votes
1answer
2k views

Convert a string in time format to minutes

I am new to C#. I just created a method where I can convert a string with the format HH:MM AM/PM to minutes. I was wondering if there is a better or more effective way to achieve the same result. <...
2
votes
2answers
83 views

Pounds-to-tons converter

Finished my first lone project and I'm wondering if the execution is passable. This is a basic lbs to tons converter. The customer drives on the scale loaded, then dumps the load and returns unloaded ...
3
votes
1answer
83 views

Enhancing a Conversion calculator

Could I please have some ideas how to improve this conversion calculator I have made. I am currently not looking to add any more quantities, but rather trying to enhance the usability and add some ...
5
votes
1answer
72 views

Pretty print uptime given seconds and omit unnecessary strings

Given an integer number of seconds, return a string which represents in human readable format the number of days/hours/minutes/seconds that are equivalent. ...
4
votes
2answers
87 views

Function to convert strings from hmmss, mmss, ss format to milliseconds

Here's the current logic to convert strings in the format hh:mm:ss, mm:ss or ss to ...
14
votes
5answers
980 views

Struct for angles

I would like to ask about the code below: ...
4
votes
2answers
2k views

Convert geodetic coordinates to geocentric (cartesian)

I'd like to retain as much float precision as possible without having to resort to specialized libraries so I need this code to work with only standard modules. I'm doing this in QGIS where ...
4
votes
1answer
197 views

Simple unit converter and shipment builder

My first python program top to bottom used for work. First it converts units from imperial to metric and vice versa, then adds the dimensions to a shipment and prints the shipment. When you do a new ...
8
votes
3answers
1k views

Temperature converter using “switch” statement

I wrote a program to convert temperature into different units, where the users have to put a space between temperature and unit: 23 f, 34 c, 45 k ...
8
votes
1answer
856 views

Python beginner code for a currrency converter

I am also pretty new to Python so I want to show my code for a very small currency converter with an Tkinter GUI. The code does what I want, but now I want to optimize it and find new "next level" ...
13
votes
5answers
4k views

Temperature unit conversion (C,F,K) in C++ - follow-up

Link to my first question: Converting Celsius and Fahrenheit in C++ I've improved my code, following @Jamal's recommendations. I hope I did everything right. The only thing I didn't get was putting ...
6
votes
1answer
334 views

Converting Celsius and Fahrenheit in C++

I've made my first little program written in C++ and was wondering if anyone could evaluate it and suggest some improvements. No copy paste. I was wondering if I can do something with my little ...
3
votes
1answer
283 views

Temperature converter with JavaScript

This is one of my first simple javascript projects. Feedback is appreciated! Basically, everytime the select option is changed, the result is shown. ...
1
vote
0answers
95 views

Binary, octal, decimal, and hexadecimal conversion in Elisp

Every once in a while I need to convert numbers between bases. As far as I'm aware there are no existing commands that let you do this in Emacs, so I added some. These functions convert numbers at ...
2
votes
2answers
636 views

Temperature conversion in JavaScript

I've made a simple console application using JavaScript, NodeJS and yargs. index.js This is the startup file. ...
1
vote
1answer
49 views

Bash time converter

This is a simple script to convert a given unit of time to other units of time. I wrote this mainly to practice writing scripts that incorporate positional parameters. It actually turned out better ...
3
votes
2answers
212 views

French Republican date conversion

This program converts a date given from the French Republican Calendar to the corresponding date in our standard Gregorian Calendar. I'm looking for some improvements that I should start making in my ...
2
votes
0answers
44 views

Module for converting between three currencies

I am creating a simple currency converter, which accepts only 3 currencies. Everything is working fine, just my code doesn't look so good. I tried to wrap it revealing module pattern, and still ...
4
votes
1answer
77 views

Converting between different units of temperature

The task is to convert a temperature in a list of Fahrenheit, Celsius, or Kelvin to the two other temperatures in the list. Here is my code: ...
0
votes
2answers
140 views

Age converter for some planets

I was wondering if it is better to use: ...
1
vote
0answers
113 views

Racket - temperature value converter

I'm giving myself programming challenges in various languages so that I can become a better problem solver i.e. focusing on problem abstraction and algorithm design, using various programming ...
4
votes
2answers
901 views

Temperature value converter

I'm trying to improve my programming skills (not just using one language). I don't have a group of other programmers to bounce ideas off other than on the web - so please forgive me if I have posted ...
6
votes
3answers
626 views

Animal Age Calculator

Could someone suggest ways to simplify this code, or any other tips? All help is much appreciated. Moreover, should I comment code above or below the line of code (I have to comment as this is a ...
2
votes
2answers
1k views

Unit conversion application

I have a form with listboxes used for unit conversions. I'm using the UnitsNet package. Here are my questions: Is this the proper approach? If any changes must be made to this code, what are they? <...
5
votes
1answer
4k views

Currency Converter in Python 3

Beginner Python developer here. I was tinkering around with Python and decided to build a currency converter. It takes in input from the user and prints out the converted currency values. The fixer.io ...
11
votes
4answers
3k views

Temperature conversion code

I am currently creating a program that can convert different units of measurement for temperature. It includes conversions for Celsius, Fahrenheit, kelvin and gas mark. Can someone tell me how I could ...
7
votes
4answers
4k views

Converting between miles, meters, inches, yards and feet

I am trying to use a class to convert between miles, meters, inches, yards and feet. My instructor told me that I have way too many functions My return statements are not storing any values and My ...
9
votes
8answers
2k views

Temperature conversion application

I'm two months in a programming course and our instructor told us we should think about building real-world applications as to gain valuable experience. I got the idea of doing a simple temperature ...
5
votes
2answers
463 views

Celsius and Fahrenheit Conversion

This is a school project submitted last year, and I've been looking over it and trying to figure out what I could improve on. I know I used celsiusInput and ...
4
votes
2answers
1k views

Parsing and converting DMS Coordinates from String to Double

I have some coordinates looking like N47° 15' 36.75",E011° 20' 38.28",+001906.00 and I've created a class to parse and convert them to Double: ...
4
votes
3answers
2k views

Swing Temperature Converter

I made a simple temperature converter to serve as an introduction to swing. I used Eclipse WindowBuilder and did not attempt to make the components more modular. I'm curious as to how you guys would ...