Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [unit-conversion]

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

Filter by
Sorted by
Tagged with
2 votes
1 answer
54 views

Basic rust Celsius to Fahrenheit conversion

I've been following the rust book, and I made a Celsius to Fahrenheit converter as it advised me. After a bit, I came up with this code; however in my opinion, there's a lot of unnecessary parts that ...
4 votes
1 answer
333 views

Yet another Fahrenheit and Celsius converter

Introduction I am recently learning Rust by reading The Rust Programming Language (a.k.a. the book). I have finished the first three chapters so far, and this is my attempt for the first exercise ...
5 votes
3 answers
682 views

Temperature unit conversion in Rust

Below is a simple Rust program which inter-converts temperature between the Celsius scale and the Fahrenheit scale. It takes two inputs: scale referring to the temperature scale of the next input the ...
0 votes
1 answer
52 views

Python 3.10+: an exploration of meta classes and subclasses through the lens of metric (SI) prefixes with subclass-able units and changeable bases

Problem Statement From the National Institute of Standards and Technology's Office of Weights and Measures, one can find a handy list of all the metric prefixes: e.g. Purpose Name Symbol Factor Name ...
1 vote
2 answers
105 views

Temperature Scale Converter in Clojure

Problem statement: Write a program that converts all given temperatures from a given input temperature scale to a given output temperature scale. The temperature scales to be supported are Kelvin, ...
0 votes
1 answer
121 views

Celsius Fahrenheit converter

I'm trying to learn Rust and for this reason I'm reading the Rust Book. It contains the following exercise: Convert temperatures between Fahrenheit and Celsius. Here's my take. Note I'm only using ...
4 votes
3 answers
4k 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 ...
2 votes
2 answers
361 views

Temperature Scale Converter in Kotlin

Problem statement: Write a program that converts all given temperatures from a given input temperature scale to a given output temperature scale. The temperature scales to be supported are Kelvin, ...
2 votes
0 answers
292 views

Temperature Scale Converter in Prolog

Problem statement: Write a program that converts all given temperatures from a given input temperature scale to a given output temperature scale. The temperature scales to be supported are Kelvin, ...
0 votes
1 answer
92 views

Temperature Scale Converter in C

Problem statement: Write a program that converts all given temperatures from a given input temperature scale to a given output temperature scale. The temperature scales to be supported are Kelvin, ...
0 votes
2 answers
262 views

Temperature Scale Converter in C++

Problem statement: Write a program that converts all given temperatures from a given input temperature scale to a given output temperature scale. The temperature scales to be supported are Kelvin, ...
1 vote
2 answers
157 views

Temperature Scale Converter in Java (for 8 scales)

Problem statement: Write a program that converts all given temperatures from a given input temperature scale to a given output temperature scale. The temperature scales to be supported are Kelvin, ...
1 vote
1 answer
82 views

Temperature Scale Converter in Rust

Problem statement: Write a program that converts all given temperatures from a given input temperature scale to a given output temperature scale. The temperature scales to be supported are Kelvin, ...
3 votes
2 answers
469 views

Temperature Scale Converter in Python

Problem statement: Write a program that converts all given temperatures from a given input temperature scale to a given output temperature scale. The temperature scales to be supported are Kelvin, ...
8 votes
2 answers
4k 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? ...
5 votes
3 answers
470 views

Templatizing a Timer class

I'm making a timer class in C++. This is the overview: ...
2 votes
2 answers
203 views

Python - Temperature - descriptors with conversion

So I'm trying to understand the concept of descriptors and gathered some code together and made an exampel out of different sources. Like the offical documentation and StackOverflow answers. I'd hope ...
4 votes
2 answers
9k 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. <...
1 vote
2 answers
162 views

Time Converter - Python Tkinter - General comments on code

I have been learning python since being in lockdown, this is the first Tkinter application I've built without consulting the internet or seeking help anywhere. It is a time converter where you can ...
2 votes
3 answers
383 views

HTML/JavaScript temperature converter with rounding

I am looking to improve the performance of my code through best practices and cleaner code. My goal here is just to perform a conversion whenever there is a keyup. But I noticed that my code looks ...
6 votes
4 answers
2k views

Bytes to binary conversion function

I created a quick function to convert n bytes into binary for my student. She is not on that level yet, but I think it would be best for her if my demonstrative ...
4 votes
1 answer
1k views

Java Temperature Converter

I have made a program that converts Celsius to Fahrenheit and Fahrenheit to Celsius. How is my code? ...
6 votes
2 answers
421 views

Pythonic attempt at conversion of length

I'm trying to learn Python, so I started with a program to convert length units, mixing imperial and metric. First I wrote a bunch of small simple functions, but then I wanted to solve the issue of ...
5 votes
2 answers
126 views

Code to support different measurement systems

I am developing an application in which the user can use different measurement systems. Currently, there is support for the metric and imperial measurement systems. To support these systems, I wrote ...
3 votes
1 answer
556 views

Convert a binary string, with each char separated by spaces, into a normal C string and print

This code is a purely for-fun project and it comes from this challenge at freeCodeCamp. This is simply an algorithm challenge which is usually meant for JavaScript, but I decided to perform in C. It ...
6 votes
3 answers
4k views

Fahrenheit / Celsius temperature converter

This is a simple bash script (hopefully with a little style as well) for converting temperatures from Fahrenheit to Celsius and vice versa. ...
4 votes
1 answer
370 views

fasm convert hex byte to binary string

This fasm x64 (Linux) code seems very crude and repetitive, but it gets the job done. How could I perform this task in a more idiomatic manner? ...
11 votes
3 answers
162 views

Mass and length calculator using Perl 6 custom operator

I am studying chemistry in the university, and then I try to write all the things in the textbook with Perl6 or Perl, like balancing the chemical formula or other process! Then I encountered the ...
4 votes
2 answers
254 views

Two classes to avoid confusion when handling degrees and radians

Experimenting with operator overloading for the first time. Based on my reading, it appears to be a bit of a minefield. Have I fallen into any traps? ...
6 votes
2 answers
3k views

Angular control for inputting latitude and longitude with validation

I've built a custom control to handle user input in a human-readable format, but save in a machine-format. It needs to have input validation, and to convert UI-input to a base format. I'm interested ...
7 votes
2 answers
355 views

Java command-line API client to fetch Bitcoin exchange rates

I am building a simple Java command-line application. And I want to know the best practice and make my code clean. Can anybody suggest to me how many different classes I can make and what more method ...
1 vote
1 answer
238 views

What should I change in my currency converter? [closed]

I wrote a simple currency converter in Python. Right now, my currency converter converts using the last available rate or converts using a specific date. Looking for: I'd appreciate any tips ...
4 votes
2 answers
155 views

Convert light-years to other representations

the code is very messy, long and I am looking how to shorten it and/or simplify it. There are a lot of repeated variables, for example; 'hourToDay' and then 'hourToDay1', 'hourToDay2' and so forth. ...
2 votes
1 answer
161 views

Temperature and currency converters in OOP JS

I just started learning OOP from Mosh on YouTube and I looked for easiest exercises to practice. Can I get a feedback on my code please? What I did wrong and what I should change? In the code there ...
11 votes
3 answers
4k views

Convert a string like 4h53m12s to a total number of seconds in JavaScript

At the moment I have this: ...
3 votes
2 answers
284 views

Simple OOP currency converter - follow-up

This is a follow up question on this post This is what I changed on my previous code: I use Exchanger and PairCurrency class ...
7 votes
2 answers
3k views

Simple OOP currency converter

I am learning about OOP so it would be great if you can give me feedback on how to improve my code and OOP design. This is a currency converter. Firstly, it will call a method to add 2 currencies and ...
5 votes
2 answers
505 views

"Nice Angles" - Code Eval challenge

Out of fun, I solved "Nice Angles" challenge on CodeEval in C# 4.0: CHALLENGE DESCRIPTION: Write a program that outputs the value of angle, reducing its fractional part to minutes and ...
4 votes
2 answers
169 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
3 answers
7k 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 ...
6 votes
3 answers
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 ...
4 votes
0 answers
740 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: ...
6 votes
0 answers
198 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 ...
3 votes
1 answer
281 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. ...
4 votes
1 answer
582 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 ...
1 vote
1 answer
117 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
2 answers
338 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 ...
7 votes
4 answers
7k views

Currency converter using MVC pattern in C++ & QT

While understanding the MVC pattern, I came across this particular article. I thought to implement it using the C++/QT library. The intent over here is to implement/use MVC concepts in correct way. ...
3 votes
1 answer
334 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
2 answers
369 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 ...