Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3808248
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:07:06+00:00 2026-05-19T15:07:06+00:00

i need to write a couple of numpy floats to a csv-file which has

  • 0

i need to write a couple of numpy floats to a csv-file which has additional string content. therefore i dont use savetxt etc. with numpy.set_printoptions() i can only define the print behaviour, but not the str() behaviour. i know that i miss something and it cant be that hard, but i dont find a reasonable answer on the interwebs. maybe someone can point me in the right direction. heres some example code:

In [1]: import numpy as np
In [2]: foo = np.array([1.22334])

In [3]: foo
Out[3]: array([ 1.22334])

In [4]: foo[0]
Out[4]: 1.2233400000000001

In [5]: str(foo[0])
Out[5]: '1.22334'

In [6]: np.set_printoptions(precision=3)

In [7]: foo
Out[7]: array([ 1.223])

In [8]: foo[0]
Out[8]: 1.2233400000000001

In [9]: str(foo[0])
Out[9]: '1.22334'

How do i convert np.float to a nicely formatted string, which i can feed to file.write()?

kind regards,

fookatchu

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T15:07:07+00:00Added an answer on May 19, 2026 at 3:07 pm

    You can just use standard string formatting:

    >>> x = 1.2345678
    >>> '%.2f' % x
    '1.23'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write some application which will have a couple threads and these
I need to import a csv file into Firebird and I've spent a couple
I need to write an app that reads a config file with info on
I've got a large amount of data (a couple gigs) I need to write
I need to write a Windows XP/Vista application, main requirements: Just one .exe file,
I have a file I need to write to a temp location, what is
I am trying to write a .pcap file, which is something that can be
I need to write a couple DLLs that will both be accessed from a
I need to write, in JavaScript (I am using jQuery), a function that is
I need to write a small console app (patch) that turns off the print

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.