bools

package
v1.1.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2023 License: BSD-3-Clause Imports: 0 Imported by: 7

README

bools

package bools does conversion to / from booleans and other go standard types:

// ToFloat32 converts a bool to a 1 (true) or 0 (false)
func ToFloat32(b bool) float32 {
	if b {
		return 1
	}
	return 0
}

// FromFloat32 converts value to a bool, 0 = false, else true
func FromFloat32(v float32) bool {
	if v == 0 {
		return false
	}
	return true
}

Other types are: float64, int, int64, int32 -- you can cast from there as necessary.

ToString and FromString are also supported to / from "true" and "false"

Documentation

Overview

package bools does conversion to / from booleans and other go standard types

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromFloat32

func FromFloat32(v float32) bool

FromFloat32 converts value to a bool, 0 = false, else true

func FromFloat64

func FromFloat64(v float64) bool

FromFloat64 converts value to a bool, 0 = false, else true

func FromInt

func FromInt(v int) bool

FromInt converts value to a bool, 0 = false, else true

func FromInt32

func FromInt32(v int32) bool

FromInt32 converts value to a bool, 0 = false, else true

func FromInt64

func FromInt64(v int64) bool

FromInt64 converts value to a bool, 0 = false, else true

func FromString

func FromString(v string) bool

FromString converts string to a bool, "true" = true, else false

func ToFloat32

func ToFloat32(b bool) float32

ToFloat32 converts a bool to a 1 (true) or 0 (false)

func ToFloat64

func ToFloat64(b bool) float64

ToFloat64 converts a bool to a 1 (true) or 0 (false)

func ToInt

func ToInt(b bool) int

ToInt converts a bool to a 1 (true) or 0 (false)

func ToInt32

func ToInt32(b bool) int32

ToInt32 converts a bool to a 1 (true) or 0 (false)

func ToInt64

func ToInt64(b bool) int64

ToInt64 converts a bool to a 1 (true) or 0 (false)

func ToString

func ToString(b bool) string

ToString converts a bool to "true" or "false" string

Types

type BoolSetter added in v1.1.16

type BoolSetter interface {
	Booler
	// SetBool sets the value from the
	// boolean representation of the value
	SetBool(val bool)
}

A BoolSetter is a Booler that can also set its value from a bool value

type Booler added in v1.1.16

type Booler interface {
	// Bool returns the boolean
	// representation of the value
	Bool() bool
}

A Booler is a type that can return its value as a boolean value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL