Questions tagged [unit-conversion]
Code whose primary purpose is to convert quantities from one system of measurement to another
94
questions
2
votes
2
answers
108
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 ...
1
vote
2
answers
63
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
124
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
992
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
986
views
Java Temperature Converter
I have made a program that converts Celsius to Fahrenheit and Fahrenheit to Celsius. How is my code?
...
5
votes
2
answers
109
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
0
answers
182
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 ...
3
votes
1
answer
123
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 ...
7
votes
2
answers
149
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 ...
4
votes
1
answer
221
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?
...
6
votes
2
answers
2k
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
181
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 ...
4
votes
2
answers
117
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?
...
1
vote
1
answer
184
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
115
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. ...
11
votes
3
answers
3k
views
Convert a string like 4h53m12s to a total number of seconds in JavaScript
At the moment I have this:
...
3
votes
2
answers
213
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
2k
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 ...
2
votes
1
answer
119
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 ...
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 ...
14
votes
3
answers
5k
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
0
answers
633
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
0
answers
169
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
1
answer
390
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
1
answer
256
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
1
answer
58
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
282
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
1
answer
270
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
174
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
1
answer
219
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
...
7
votes
2
answers
2k
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
3
answers
129
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
2
answers
319
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
1
answer
111
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
2
answers
109
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
0
answers
49
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
1
answer
78
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
2
answers
897
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 ...
4
votes
2
answers
7k
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
2
answers
113
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
1
answer
116
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
1
answer
173
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
2
answers
105
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
5
answers
1k
views
Struct for angles
I would like to ask about the code below:
...
6
votes
2
answers
7k
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
1
answer
422
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
3
answers
2k
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
1
answer
4k
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
5
answers
5k
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
1
answer
858
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 ...