Height Conversion Tool
A simple and efficient tool for converting height measurements between different units (feet/inches, centimeters, meters).
Model Overview
This tool provides accurate height conversions between various measurement systems commonly used around the world. It supports bidirectional conversions and handles multiple input formats.
Features
- Multiple Unit Support: Convert between feet/inches, centimeters, and meters
- Flexible Input: Accepts various input formats (e.g., "5'10"", "178 cm", "1.78 m")
- High Accuracy: Maintains precision across conversions
- Easy to Use: Simple API with clear documentation
- Bilingual: Supports English and Vietnamese
Supported Conversions
| From | To | Example |
|---|---|---|
| Feet & Inches | Centimeters | 5'10" โ 177.8 cm |
| Centimeters | Feet & Inches | 180 cm โ 5'11" |
| Meters | Feet & Inches | 1.75 m โ 5'9" |
| Feet & Inches | Meters | 6'0" โ 1.83 m |
| Centimeters | Meters | 170 cm โ 1.7 m |
Installation
pip install height-conversion-tool
Or clone this repository:
git clone https://huggingface.co/NuBest/height-conversion-tool
cd height-conversion-tool
pip install -r requirements.txt
Quick Start
Python Usage
from height_converter import HeightConverter
# Initialize converter
converter = HeightConverter()
# Convert from feet/inches to centimeters
height_cm = converter.feet_to_cm(5, 10) # 5 feet 10 inches
print(f"Height: {height_cm} cm") # Output: Height: 177.8 cm
# Convert from centimeters to feet/inches
feet, inches = converter.cm_to_feet(180)
print(f"Height: {feet}'{inches}\"") # Output: Height: 5'11"
# String input format
result = converter.convert("5'10\"", to_unit="cm")
print(result) # Output: 177.8 cm
Command Line Usage
# Convert height
python height_converter.py --input "5'10\"" --output cm
# Multiple conversions
python height_converter.py --input 180 --from cm --to feet
API Reference
HeightConverter Class
Methods
feet_to_cm(feet: int, inches: float = 0) -> float
- Converts feet and inches to centimeters
- Parameters:
feet: Number of feetinches: Number of inches (optional, default: 0)
- Returns: Height in centimeters
cm_to_feet(cm: float) -> tuple[int, float]
- Converts centimeters to feet and inches
- Parameters:
cm: Height in centimeters
- Returns: Tuple of (feet, inches)
meters_to_feet(meters: float) -> tuple[int, float]
- Converts meters to feet and inches
- Parameters:
meters: Height in meters
- Returns: Tuple of (feet, inches)
convert(input_str: str, to_unit: str = "cm") -> str
- Flexible conversion from string input
- Parameters:
input_str: Height string (e.g., "5'10"", "180cm", "1.8m")to_unit: Target unit ("cm", "feet", "meters")
- Returns: Converted height as string
Use Cases
- Healthcare: Converting patient height measurements between metric and imperial systems
- Fitness Apps: Standardizing height inputs across different regions
- E-commerce: Converting size charts for international customers
- Travel Apps: Helping users understand height requirements in different countries
- Education: Teaching measurement conversions
Technical Details
Conversion Formulas
- 1 inch = 2.54 cm
- 1 foot = 12 inches = 30.48 cm
- 1 meter = 100 cm = 3.28084 feet
Accuracy
The tool maintains precision up to 2 decimal places for centimeters and meters, and up to 1 decimal place for inches.
Examples
Example 1: Basic Conversion
from height_converter import HeightConverter
converter = HeightConverter()
# Convert 6 feet to centimeters
result = converter.feet_to_cm(6, 0)
print(f"6 feet = {result} cm") # Output: 6 feet = 182.88 cm
Example 2: Batch Conversion
heights_cm = [150, 160, 170, 180, 190]
for height in heights_cm:
feet, inches = converter.cm_to_feet(height)
print(f"{height} cm = {feet}'{inches:.1f}\"")
Output:
150 cm = 4'11.1"
160 cm = 5'3.0"
170 cm = 5'7.0"
180 cm = 5'10.9"
190 cm = 6'2.8"
Example 3: Web Integration
from flask import Flask, request, jsonify
from height_converter import HeightConverter
app = Flask(__name__)
converter = HeightConverter()
@app.route('/convert', methods=['POST'])
def convert_height():
data = request.json
input_height = data.get('height')
to_unit = data.get('to_unit', 'cm')
result = converter.convert(input_height, to_unit)
return jsonify({'result': result})
if __name__ == '__main__':
app.run(debug=True)
Testing
Run the test suite:
python -m pytest tests/
Run specific tests:
python -m pytest tests/test_converter.py -v
Contributing
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Setup
# Clone repository
git clone https://huggingface.co/NuBest/height-conversion-tool
cd height-conversion-tool
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install development dependencies
pip install -r requirements-dev.txt
# Run tests
pytest
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Citation
If you use this tool in your research or project, please cite:
@software{height_conversion_tool,
author = {NuBest},
title = {Height Conversion Tool},
year = {2025},
url = {https://huggingface.co/NuBest/height-conversion-tool}
}
Support
- Issues: GitHub Issues
- Discussions: Community Forum
- Email: support@nubest.com
- Website: https://www.nubest.com/
Changelog
Version 1.0.0 (2025-01-29)
- Initial release
- Support for feet/inches, centimeters, and meters
- Command line interface
- Python API
- Comprehensive test suite
Acknowledgments
- Built with Python 3.8+
- Inspired by the need for accurate height conversions in international applications
- Special thanks to the Hugging Face community
FAQ
Q: What's the maximum height that can be converted? A: The tool supports heights up to 999 cm (32'9") to cover all practical use cases.
Q: How accurate are the conversions? A: Conversions maintain precision up to 2 decimal places, which is sufficient for all practical purposes.
Q: Can I use this in a commercial application? A: Yes, the Apache 2.0 license allows commercial use with proper attribution.
Q: Does it support other units like yards or kilometers? A: Currently, the tool focuses on the most commonly used units (feet/inches, cm, meters). Additional units may be added in future versions.
Q: How do I handle invalid input? A: The tool includes input validation and raises clear error messages for invalid inputs.
Made with โค๏ธ by NuBest Team