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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:37:12+00:00 2026-06-12T21:37:12+00:00

Consider a this string containing an integer nanoseconds=$(date +%s%N) when I want to strip

  • 0

Consider a this string containing an integer

nanoseconds=$(date +%s%N)

when I want to strip off the last six characters, what would be semantically better?

Stripping just the characters off the string

nanoseconds=$(date +%s%N)

milliseconds=${nanoseconds%??????}

or dividing the value by 1000000

milliseconds=$((nanoseconds / 1000000))

EDIT

Sry for not being clear. It’s basically for doing a conversion from nanoseconds to milliseconds. I think I answered my own question…

  • 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-06-12T21:37:14+00:00Added an answer on June 12, 2026 at 9:37 pm

    Both are equivalent, but in general I would consider the former method to be safer. The first method is explicit and does precisely what you want to do: to remove a substring from the back of the string.

    The other one is a mathematical operation that relies on correct rounding. Although I cannot imagine where it would fail, I would prefer the first method.

    Unless, of course, what you really want is not stripping the last three characters but dividing by 1000 🙂

    Post scriptum: hah, of course I know where it would fail. Let value=”123″. ${value%???} strips the last three digits, as intended, leaving an empty string. $(( value / 1000 )) results in value equal to "0" (a string of length of 1).

    EDIT: since we know now that it is not about stripping characters, but rounding, clearly dividing by 1000 is the correct way of approaching the problem 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this simple example - public class Person { private String name; private Date
consider this string prison break: proof of innocence (2006) {abduction (#1.10)} i just want
Consider this string, var string = "sometext/#a=some_text/#b=25/moretext"; What I would like to do is
Consider this array string[] presidents = { Adams, Arthur, Buchanan, Bush, Carter, Cleveland, Clinton,
Consider a string array shaped like this: string[] someName = new string[] { First,
Consider this case: public Class1 { public static final String ONE = ABC; public
Consider this sample class, class TargetClass { private static String SENSITIVE_DATA = sw0rdfish; private
Consider this code : class MyClass<T> { } class AnotherClass : MyClass<String> { }
Consider this code: package Prova; import java.util.ArrayList; public class Prova { private ArrayList<String> people;
If we consider a std::string implementation that uses reference counting, consider this scenario: int

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.