Skip to content
/ sinum Public

Representation of SI numbers.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

Kamduis/sinum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sinum

This Rust crate provides the SiNum type that represents numbers that can easily be represented by the International System of Units (SI, from French Système International).

Example

To use this crate your Cargo.toml could look like this:

[dependencies]
sinum = "0.1.0"

Create a prefix-aware number:

use sinum::{SiNum, Prefix};

let num = SiNum::new( 9.9 ).with_prefix( Prefix::Milli );

assert_eq!( num.as_f64(), 0.0099 );
assert_eq!( num.prefix(), Prefix::Milli );
assert_eq!( format!( "{}", num ), "9.9 m" );

A SiNum prefix can be changed, without changing the value of the number it represents:

use sinum::{SiNum,Prefix};

let num = SiNum::new( 9.9 ).to_prefix( Prefix::Milli );

assert_eq!( num.as_f64(), 9.9 );
assert_eq!( num.prefix(), Prefix::Milli );
assert_eq!( format!( "{}", num ), "9900 m" );

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

Representation of SI numbers.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages