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 6556957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:00:44+00:00 2026-05-25T13:00:44+00:00

I have a sqlite table that has amount field with NUMERIC(10,5) value(I know data

  • 0

I have a sqlite table that has amount field with NUMERIC(10,5) value(I know data type meant not much in sqlite). I want to write a select statement that display amount in 2 decimal places.

    id      name             type        notnull      dflt_value      pk   
------- --------------- ---------- ----------- -------------- --- 
0        _id              integer       0                            1    
1        name             varchar       1                            0    
2        amount           NUMERIC(10,5) 0                            0    

SELECT _id, name, amount FROM accounts

Is it possible to convert the amount in two decimal places within the select statement, so I can display with two decimal places in the application.
I need to format in the select statement, don’t wants to change the table structure. Thanks in advance.

Im using following code to populate the the list view in android

    cursor = dbAdapter.getAccountsTotals(); 
    startManagingCursor(cursor); 
    String[] from = new String[] { DbAdapter.KEY_ID, DbAdapter.KEY_NAME, DbAdapter.KEY_AMOUNT}; 
    int[] to = new int[] { R.id.dis1, R.id.dis2, R.id.dis3}; 
    SimpleCursorAdapter trans = new SimpleCursorAdapter(this, R.layout.accts_row, cursor, from, to); 
setListAdapter(trans); 

so can not format the results after fetching form the database. Please let me know it there is a way to assign formatted values in above code, thanks.

  • 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-25T13:00:45+00:00Added an answer on May 25, 2026 at 1:00 pm
    SELECT _id, name, ROUND(amount,2) FROM accounts
    

    Following code will give you idea how you can do it

        
    
    public class TestListView extends ListActivity {
      ...
      private DecimalFormat myCustDecFormatter = new DecimalFormat("########.00");
      ...
      ...
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState)  {
        ...
        ...
        ...
      }
    
    private void fillData() {
        /* Get all of the rows from the database and create the item list */
        /* for mult accts, pass in acct name? */
        mEntryCursor = mDbHelper.fetchAllEntries();
        startManagingCursor(mEntryCursor);
    
        // Create an array to specify the fields we want to display in the list (only TITLE)
        String[] from = new String[]{myDbAdapter.KEY_NMBR,myDbAdapter.KEY_DATE,myDbAdapter.KEY_DESCR,myDbAdapter.KEY_AMT};
    
        // and an array of the fields we want to bind those fields to (in this case just text1)
        int[] to = new int[]{R.id.txtnmbr, R.id.txtdate, R.id.txtdescr, R.id.txtamt};
    
        // Now create a simple cursor adapter and set it to display
        setListAdapter(new SimpleCursorAdapter(this, R.layout.entryrow, mEntryCursor, from, to) {
            @Override
            public void setViewText(TextView v, String text) {
              super.setViewText(v, convText(v, text));
            }
    
        });
    
      }
    
      private String convText(TextView v, String text) {
        switch (v.getId()) {
          case R.id.txtamt:
            double dblAmt;
            //dblAmt = Double.valueOf(text);
            dblAmt = mEntryCursor.getDouble(AMT_COLUMN);
            return myCustDecFormatter.format(dblAmt);
        }
          return text;
        } 
    
    }//end TestListView
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Sqlite database that has a table consisting of company information (Companies)
I have a users table with a bitmask field that has a permissions mask
I have an SQLite table that contains a BLOB I need to do a
I have a table in my schema that has a unique constraint on two
I have created a Python module that creates and populates several SQLite tables. Now,
I have a sqlite (v3) table with this column definition: timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
I have a database file that is generated on a PC using Sqlite. This
I have two tables with a variable amount of columns. (I don't know how
I have SQLite database and I have in it certain column of type double.
I have an StackOverflowException in one of my DB functions that I don't know

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.