module Eventsims

Constants

VERSION

Public Class Methods

trimlist(*args) click to toggle source
# File lib/eventsims/discrete.rb, line 24
def self.trimlist(*args)
        ''' Takes in number list or float and removes leading zeros '''
        store = []
        values = []
        args.each{|mylist| 
                a = []
                mylist.each{|x| 
                        if x.is_a?(Float)
                                a.push(x.round(4)) 

                        elsif x.is_a?(Array)
                                inner = []
                                x.each{|y| inner.push y.is_a?(Float)? y.round(4) : y}
                                a.push(inner)

                        else a.push(x)

                        end
                }
                values.push(a)
                
        }
        store.push(values)
        return store[0]

end
trimval(thelist) click to toggle source

Removes leading zeros after decimal and/or approximate to 4dp

# File lib/eventsims/discrete.rb, line 5
def self.trimval(thelist)
        ''' Takes in number list or float and removes leading zeros '''
        #Checks if passed argument is a list
        if thelist.is_a?(Array)
                temp = []
                # Loops through each list and convert to 4dp if needed
                thelist.each{|i| temp.push i.is_a?(Float)? i.round(4) : i}    
                thelist = temp
                return thelist

        elsif thelist.is_a?(Float)
                return thelist.round(4)

        else
                return thelist
        end

end