Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Location latitude and logitude precision returns less decimals than provided precision #3373

Open
7 of 10 tasks
atilajanosi opened this issue Jan 15, 2025 · 2 comments
Open
7 of 10 tasks
Labels
m: location Something is referring to the location module p: 1-normal Nothing urgent question Further information is requested

Comments

@atilajanosi
Copy link

Pre-Checks

Describe the bug

Some of our services are expecting latitude/longitude with 6 digit precision.

faker.latitude(longitude) has a prop to generate with specified precision but in case of last digit 0 the digit is not being returned meaning that we sometimes end up with precision 5.

image

Minimal reproduction code

const { faker } = require('@faker-js/faker')
for(let i=0;i<100;i++) {
	let latitude = '' + faker.location.latitude({ max: 64.856941, min: 19.501391, precision: 6 })
	console.log(latitude)
}

Additional Context

No response

Environment Info

System: macOS Sequoia Version 15.2
Node: v18.20.2
NPM: 10.5.0
Faker: "@faker-js/faker": "9.3.0"

Which module system do you use?

  • CJS
  • ESM

Used Package Manager

npm

@atilajanosi atilajanosi added c: bug Something isn't working s: pending triage Pending Triage labels Jan 15, 2025
@matthewmayer
Copy link
Contributor

That's how JavaScript floating point numbers work. If you want to force the trailing zeros to appear, add a .toFixed(6) on the end

@ST-DDT ST-DDT added question Further information is requested p: 1-normal Nothing urgent m: location Something is referring to the location module and removed c: bug Something isn't working s: pending triage Pending Triage labels Jan 16, 2025
@ST-DDT
Copy link
Member

ST-DDT commented Jan 16, 2025

@atilajanosi Does this answer your question/resolve your issues?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
m: location Something is referring to the location module p: 1-normal Nothing urgent question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants