help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
go-cli-tool
/
internal
/
conv
RSK World
go-cli-tool
Go CLI Tool v3.0 - Command-Line Interface with File Operations + Text Processing + System Monitoring + Cryptographic Tools + Network Utilities + HTTP Client + Image Processing + Cross-Platform Support + Modern Go Development
conv
  • unit.go2.3 KB
unit.go
internal/conv/unit.go
Raw Download
Find: Go to:
/*
 * Project: Go CLI Tool
 * Category: Go Projects
 * Description: Command-line interface tool built with Go. Features file operations, text processing, command parsing, and system utilities.
 * Author: RSK World
 * Email: support@rskworld.in
 * Website: https://rskworld.in/contact.php
 * Year: 2026
 * Copyright (c) 2026 RSK World. All rights reserved.
 */

package conv

import (
	"fmt"
	"strings"
)

// CelsiusToFahrenheit converts temperature from C to F.
func CelsiusToFahrenheit(c float64) {
	f := (c * 9 / 5) + 32
	fmt.Printf("%.2f°C is %.2f°F\n", c, f)
}

// FahrenheitToCelsius converts temperature from F to C.
func FahrenheitToCelsius(f float64) {
	c := (f - 32) * 5 / 9
	fmt.Printf("%.2f°F is %.2f°C\n", f, c)
}

// MetersToFeet converts length from Meters to Feet.
func MetersToFeet(m float64) {
	ft := m * 3.28084
	fmt.Printf("%.2fm is %.2fft\n", m, ft)
}

// FeetToMeters converts length from Feet to Meters.
func FeetToMeters(ft float64) {
	m := ft / 3.28084
	fmt.Printf("%.2fft is %.2fm\n", ft, m)
}

// KgToLb converts weight from Kilograms to Pounds.
func KgToLb(kg float64) {
	lb := kg * 2.20462
	fmt.Printf("%.2fkg is %.2flb\n", kg, lb)
}

// LbToKg converts weight from Pounds to Kilograms.
func LbToKg(lb float64) {
	kg := lb / 2.20462
	fmt.Printf("%.2flb is %.2fkg\n", lb, kg)
}

// BytesToHuman converts bytes to human readable format.
func BytesToHuman(bytes float64) {
	units := []string{"B", "KB", "MB", "GB", "TB"}
	size := bytes
	unitIndex := 0

	for size >= 1024 && unitIndex < len(units)-1 {
		size /= 1024
		unitIndex++
	}

	fmt.Printf("%.2f bytes is %.2f %s\n", bytes, size, units[unitIndex])
}

// HumanToBytes converts human readable size to bytes.
func HumanToBytes(size float64, unit string) {
	multipliers := map[string]float64{
		"b": 1, "B": 1,
		"kb": 1024, "KB": 1024, "k": 1024, "K": 1024,
		"mb": 1024 * 1024, "MB": 1024 * 1024, "m": 1024 * 1024, "M": 1024 * 1024,
		"gb": 1024 * 1024 * 1024, "GB": 1024 * 1024 * 1024, "g": 1024 * 1024 * 1024, "G": 1024 * 1024 * 1024,
	}

	multiplier, exists := multipliers[strings.ToLower(unit)]
	if !exists {
		fmt.Printf("Unknown unit: %s\n", unit)
		return
	}

	bytes := size * multiplier
	fmt.Printf("%.2f %s is %.0f bytes\n", size, strings.ToUpper(unit), bytes)
}
87 lines•2.3 KB
go

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer