Skip to content

Commit

Permalink
Readd decimal_part() and leading_zero_number() returning strings
Browse files Browse the repository at this point in the history
  • Loading branch information
vbrazo committed Jul 10, 2019
1 parent 73d6e3d commit 8649b98
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
10 changes: 5 additions & 5 deletions doc/default/number.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
```ruby
# Required parameter: digits
# Produces a number of the specified digits where the leading digit is never 0
Faker::Number.number(10) #=> "1968353479"
Faker::Number.number(10) #=> 1968353479

# Required parameter: digits
# Produces a number of the specified digits with a leading zero
Expand All @@ -15,10 +15,10 @@ Faker::Number.decimal_part(2) #=> "09"

# Required parameter: l_digits
# Produces a number with 2 digits leading and trailing the decimal
Faker::Number.decimal(2) #=> "11.88"
Faker::Number.decimal(2) #=> 11.88

# Specify different values for leading and trailing digits
Faker::Number.decimal(2, 3) #=> "18.843"
Faker::Number.decimal(3, 3) #=> 181.843

# Required parameters: mean, standard_deviation
Faker::Number.normal(50, 3.5) #=> 47.14669604069156
Expand All @@ -38,7 +38,7 @@ Faker::Number.positive #=> 235.59238499107653

Faker::Number.negative #=> -4480.042585669558

Faker::Number.non_zero_digit #=> "8"
Faker::Number.non_zero_digit #=> 8

Faker::Number.digit #=> "1"
Faker::Number.digit #=> 1
```
13 changes: 13 additions & 0 deletions lib/faker/default/number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ def number(digits = 10)
([non_zero_digit] + generate(digits - 1)).join.to_i
end

def leading_zero_number(digits = 10)
'0' + (2..digits).collect { digit }.join
end

def decimal_part(digits = 10)
num = ''
if digits > 1
num = non_zero_digit
digits -= 1
end
leading_zero_number(digits) + num
end

def decimal(l_digits = 5, r_digits = 2)
l_d = number(l_digits).to_s
r_d = if r_digits == 1
Expand Down

0 comments on commit 8649b98

Please sign in to comment.